I am currently working on a Javascript code snippet that aims to find specific strings in an array.
var test = ['hello', 'my', 'name'];
for (var i = 0; i < data.length; i++) {
if (test === "name") {
//In the array!
ct = "found";
} else {
ct = "not found";
}
};
The main goal here is to iterate through an array of results, let's say 100 items in total, and check whether the variable test
includes the string 'name' or not.
After running this code snippet, I checked the console log and realized that it always displays the value of ct
as 'not found'.
This piece of code is essential for determining how many occurrences of a specific string defined by test
can be found within an array.