JSFiddle - React, Tailwind, and code Playground
by Jessie Lau
JavaScript
function returnPosition(myArr, str){
var positions = [];
for(var i = 0; i < myArr.length; i++){
var cur = myArr[i];
if(str == cur){
positions.push(myArr.indexOf(cur));
}
}
return positions;
}
var a = ["a", "b", "a", "a"];
var s = "a";
var res = returnPosition(a, s);
console.log(res);