I have JavaScript code like this:
var arrayku = new Array();
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return [i, sParameterName[0], sParameterName[1]]; //i is id, sParameterName[0] is first 2nd param, sParameterName[1] is third param
}
}
The Question is how to:
Put variable
i,sParameterName[0],sParameterName[1]into array of key and value and I want variableias the key.How to get all value of
arraykuin a loop?
Spencer Wieczorek
21.6k7 gold badges46 silver badges57 bronze badges
1 Answer 1
Use push() to add the elements to the array in the loop.
var arrayku = new Array();
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
arrayku.push( [i, sParameterName[0], sParameterName[1]]); //i is id, sParameterName[0] is first 2nd param, sParameterName[1] is third param
}
}
console.log(arrayku);
answered Feb 4, 2015 at 18:26
epascarello
208k20 gold badges206 silver badges246 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Devisy
hi epascarello, thanks for the answer, how to access and display arrayku?
epascarello
It is a array of objects.... You access it like an Array? Not sure how you want to display it...
lang-js
arraykuthe same way you get all the values ofsURLVariables?