Very new to Javascript and coding in general!
I'm basically looking to test strings within an array, if and when a string returns a certain value I then want to get the index of that string within the array and store the indexes within another variable.
The problem I'm having (I think) is that I'm unsure of the correct syntax to extract and push the index once I've confirmed that it's the string I'm looking for ... Apologies in advance if I've not explained myself very well.
Here's what I have:
let freightItems = ['contraband', 'clear', 'contraband', 'clear'];
function scan(freightItems) {
let contrabandIndexes = [];
freightItems.forEach(str => {
if (str === 'contraband') {
freightItems.push(contrabandIndexes);
}
})
return contrabandIndexes;
}
console.log(scan(freightItems))