Goal: 1) Create a string using the ID attributes of several elements. 2) Push that string to an array. 3) Check to see if the string in the array forms a particular word -- in this case, "idaho".
Problem: I can only seem to verify that a particular character is in the array. If I use more than one character in the "value" of "$.inArray", it returns false.
Question: How can I verify that the string in the array forms the word "idaho" instead of just verifying that the string contains an "i" or "d" or "a", etc.?
This FIDDLE works, but only because it's looking for an "i" instead of "idaho".
I've done a lot of research on this, but can't get it to work. Thanks for helping a noob!
<div class="pieces" id="i"></div>
<div class="pieces" id="d"></div>
<div class="pieces" id="a"></div>
<div class="pieces" id="h"></div>
<div class="pieces" id="o"></div>
var piecesArray = [];
var ids = $('.pieces').map(function() {
piecesArray.push(this.id);
});
piecesArray = piecesArray.join('');
if ($.inArray('i', piecesArray) !==-1){
alert(piecesArray);
}
piecesArray === 'idaho'? Note that after usingjoinyou have a string not a real array.