How to know the index of the found value and realize the value search index?

There are 2 array.
And 2 tasks:
1. in info should bear index was found in order to find the value of the same index in new_price
2. To implement searching values new_price index new_id

new_id = ["6735852414", "6718911044", "6708286210", "6685544128", "6685509726", "6681018667", "6681017650", "6680386705", "6680386639", "6680361952", "6656904312", "6656902968", "6640248456"]

new_price = ["145.41", "166.80", "680.01", "1005.05", "332.88", "72.71", "72.71", "72.71", "72.71", "72.71", "71.28", "71.28", "78.41"]

new_id.forEach(function(item, i, arr){
 if ('6708286210' == item){
// in the info should bear index was found in order to find the value of the same index in new_price 
var info; 
 }else{return false}
});

 new_price.forEach(function(item2, i, arr){
 // How to implement an index search with the new_id.forEach to get the value of new_price ?
 });
July 8th 19 at 11:20
3 answers
July 8th 19 at 11:22
Do not quite understand your description of the problem. To find the matching elements in the two arrays, you can use a similar design:
var intersect = array1.filter(item => arr2.indexOf(item) != -1);

intersect will contain an array of all matching elements.
July 8th 19 at 11:24
this_price = new_price[new_id.indexOf('6718911044')];
In the variable this_price will be the price corresponding to the object with id = 6718911044.
var info_id = parseFloat($(this).data('item-id'));

How to substitute the value in this_price info_id = new_price[new_id.indexOf('HERE')]; - clemens66 commented on July 8th 19 at 11:27
: info_id in this_price = new_price[new_id.indexOf(info_id)]; - kiley_Gottli commented on July 8th 19 at 11:30
tried, get this_price = undefined - clemens66 commented on July 8th 19 at 11:33
Thanks for the help, actually translated to string and began to work. - clemens66 commented on July 8th 19 at 11:36
: if helped, click to Mark with a solution - kiley_Gottli commented on July 8th 19 at 11:39
July 8th 19 at 11:26
To find the index of the first occurrence, you can use the String.prototype.indexOf()
If the value is not found - returns -1. From this and dance. (Well, if I correctly understood the task).
How to search by index value? - clemens66 commented on July 8th 19 at 11:29
: indexOf() returns the index (position item in the array), unless of course the item is. If not, return -1.
To obtain the value at index: element = arr[index]; - kiley_Gottli commented on July 8th 19 at 11:32

Find more questions by tags JavaScript