Web Development with jQuery®

(Elliott) #1

Array Utility Methods (^) ❘ 159
returns –1 (minus one). The following example, Example 5-10, demonstrates how jQuery’s inAr-
ray() method works:
<!DOCTYPE HTML>






$.inArray()







The following JavaScript demonstrates $.inArray():
$(document).ready(
function()
{
var songs = [
'Taxman',
'Eleanor Rigby',
'I\'m Only Sleeping',
'Love You To',
'Here, There and Everywhere',
'Yellow Submarine',
'She Said, She Said',
'Good Day Sunshine',
'And Your Bird Can Sing',
'For No One',
'Doctor Robert',
'I Want to Tell You',
'Got to Get You into My Life',
'Tomorrow Never Knows'
];
console.log(
'Love You To: ' + (
$.inArray('Love You To', songs)
)
);
console.log(
'Strawberry Fields Forever: ' + (
$.inArray('Strawberry Fields Forever', songs)
)
);
}
);
[http://www.it-ebooks.info](http://www.it-ebooks.info)
Free download pdf