JavaScript How to find the position of each array object using Nodejs

How can i return array position of each object in an array.

code

let targets = [1.2, 2.3, 3.5];
let targetUpdatedOn = [2018-07-06, 2018-07-06, 2018-07-06];
let liveCoinPrice = 1.3;

let targets_hit = targets.filter(function(target_value) {
  return liveCoinPrice >= target_value;
});

This what is done to find array position.

targets_hit.forEach(function(key) { 

   if(targetUpdatedOn[key] === undefined){ 
       console.log(targetUpdatedOn); 
    } 
} 

I want to return array position of each targets_hits . Any help would be thankful.

Answer:1

You can just do this.

targets_hit.forEach((item, index) => {
    console.log(item, index); // Item and index
    console.log(index) // Index only
});

The forEach method callback has 3 parameters.

  1. Current Value
  2. Index (Optional)
  3. Array being traversed (Optional)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

Answer:2

I got an image in canvas. I need to scale my image to the top, to the bottom, to the left and to the right differently. Function drawImage has only width and height parameters, but not top, bottom, ...

I got an image in canvas. I need to scale my image to the top, to the bottom, to the left and to the right differently. Function drawImage has only width and height parameters, but not top, bottom, ...

I'm drawing a dashed line and a dashed rect in fabricjs, but there is an issue when setting the strokeWidth too high for the line/rect to draw the strokeDashArray properly. Example: if ...

I'm drawing a dashed line and a dashed rect in fabricjs, but there is an issue when setting the strokeWidth too high for the line/rect to draw the strokeDashArray properly. Example: if ...

I've recently started using Ramda to work with responses from JSONAPI and I am having some trouble dealing with complex relationships.. I have a big array with three smaller arrays, and I need to ...

I've recently started using Ramda to work with responses from JSONAPI and I am having some trouble dealing with complex relationships.. I have a big array with three smaller arrays, and I need to ...

  1. merge three arrays javascript
  2. merge three arrays php
  3. merge three arrays python
  4. merge three arrays
  5. merge three arrays java
  6. merge three arrays in js
  7. merge three arrays c#
  8. merge three sorted arrays
  9. numpy merge three arrays
  10. php merge three arrays into one
  11. merge three sorted arrays java
  12. jquery merge three arrays

I am going to check if an html element contains it's own text. Examples are <div>Text<tag></tag>Text</div> and <div>Text</div>. Some thing that not fit is <...

I am going to check if an html element contains it's own text. Examples are <div>Text<tag></tag>Text</div> and <div>Text</div>. Some thing that not fit is <...

  1. check html element type
  2. check html element exists javascript
  3. check html element has class
  4. check html element exists jquery
  5. check html element type jquery
  6. check html element
  7. check html element visible
  8. check html element attribute
  9. check html element visible jquery
  10. check html element present jquery
  11. check html element exist
  12. check html element jquery
  13. check html element value
  14. check html element color
  15. html check element has focus
  16. check if html element exists jquery
  17. check if html element exists
  18. check if html element is visible
  19. check if html element has class
  20. check if html element exists javascript