0

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:

  1. Put variable i, sParameterName[0], sParameterName[1] into array of key and value and I want variable i as the key.

  2. How to get all value of arrayku in a loop?

2
  • push Commented Feb 4, 2015 at 18:24
  • Devi, your question isn't clear. By "array of key and value" do you mean an Object, which is what Javascript uses for an associative array? Why can't you get all the values of arrayku the same way you get all the values of sURLVariables? Commented Feb 4, 2015 at 18:31

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

hi epascarello, thanks for the answer, how to access and display arrayku?
It is a array of objects.... You access it like an Array? Not sure how you want to display it...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.