Javascript examples for Array Operation:Associative Array
Return number for each letter in a string
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {//w ww .ja v a2 s . c om var alphabet = { a: 1, b: 2, c: 3 } var word = "aab"; var total = 0; for (var i = 0; i < word.length; i++) total += alphabet[word[i]]; console.log(total); }); </script> </head> <body> </body> </html>