I would like to take an array of strings, get them out of an array and set them all to zero.
The initial array is:
var anArray = ["hello", "can", "you", "hear", "me"];
and the desired output would be:
var hello = 0;
var can = 0;
var you = 0;
var hear = 0;
var me = 0;
I thought by looping through the array, I could call a new variable and set equal to zero but I'm not sure how that is done.
How can this be done?
FWIW, the purpose of this is to use all of these zeros later as counters.
var anArray = ["hello", "can", "you", "hear", "me"];
var secondArray = 0;
$(document).ready(function() {
for (var i = 0; i < anArray.length; i++) {
var array[i] = 0;
secondArray.push(array[i]);
};
console.log(secondArray);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>