JSFiddle - React, Tailwind, and code Playground
by David Thomas
JavaScript
var array1 = ["50", "51", "52", "53", "54", "55", "56", "57", "58", "59"],
array2 = ["59", "55", "51"];
function getIndicesOfCommonArrayValues(one, two) {
if ([one, two].every(function (arr) {
return 'undefined' !== typeof arr && arr.constructor === Array;
})) {
var longestArray = one.length >= two.length ? one : two,
shortestArray = one.length < two.length ? one : two;
return shortestArray.map(function (value) {
if (longestArray.indexOf(value) > -1) {
return longestArray.indexOf(value);
}
});
}
}
console.log(getIndicesOfCommonArrayValues(array1, array2));