1

My array:-

var data = [
    [4, "Shailesh ", "Sharma"],
    [5, "Devesh Kumar ", "Neema"],
    [6, "Vardan S ", "Khanna"],
    [208, "Kamlesh ", "Lohiya"],
    [210, "Raj Bahadur ", "Singh"]
]
1
  • 1
    Hi @parth welcome to SO :-) Can you please add what code you have already tried yourself to do this? At SO we are here to help with code you already have. Commented Sep 18, 2015 at 14:06

3 Answers 3

5

You can simply do this using jQuery.each() like:

var data = [
    [4, "Shailesh ", "Sharma"],
    [5, "Devesh Kumar ", "Neema"],
    [6, "Vardan S ", "Khanna"],
    [208, "Kamlesh ", "Lohiya"],
    [210, "Raj Bahadur ", "Singh"]
]

$.each(data, function (i, n) {
    $.each(n, function (i2, n2) {
        console.log(i2, n2);
    });
});

EDIT:

For adding as option getting data from array

var option = '';
$.each(data, function (i, n) {
    option += '<option value="' + n[0] + '">' + n[1] + '</option>';
});
console.log(option);
$('select').append(option);
Sign up to request clarification or add additional context in comments.

4 Comments

this is giving me a single single character. i need whole value between double quotes.
@parthbhorania: can provide an example of your expected result?
i am gonna use this value in "<select><option value="4">shailesh</option><option value="5">Davesh Kumar</option></select>" .
@parthbhorania: That's simple. You can do like in the updated code above. Hope you can take from here. Cheers!
1
var a = [[4,"Shailesh ","Sharma"],[5,"Devesh Kumar ","Neema"],[6,"Vardan S ","Khanna"],[208,"Kamlesh ","Lohiya"],[210,"Raj Bahadur ","Singh"]]

for(var i=0; i<a.length;i++)
{
  for(var j=0; j<a[i].length;j++){
  console.log("value:"+a[i][j]);
  }
}

1 Comment

Correct - but doesn't use JQuery :-)
0

In plain JavaScript:

var data = [
  [4, "Shailesh ", "Sharma"],
  [5, "Devesh Kumar ", "Neema"],
  [6, "Vardan S ", "Khanna"],
  [208, "Kamlesh ", "Lohiya"],
  [210, "Raj Bahadur ", "Singh"]
];

data.forEach(function (a) {
  console.log(a[0] + a[1] + a[2]);
});

I can't really see a good reason to do it in jQuery.

Comments

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.