ineffable p
ineffable p

Reputation: 1189

jquery to conert object data into string array

I am getting data in jquery as below , I want to convert to one dimensional string Array

[
    {"2065559857":"2065559482"},
    {"2065559857":"2065553412"},
    {"2065559857":"2065558122"},
    {"2065559857":"7155354848"},
    {"2065559857":"7155577723"},
    {"2065559857":"7153555598"},
    {"2065559857":"2065551189"},
    {"2065559857":"7155544434"},
    {"2065559857":"7296363080"},
    {"2065559857":"7890128703"},
    {"2065559857":"8483894326"},
    {"2065559857":"9077659950"},
    {"2065559857":"9671425573"}
]

convert into

["2065559482","2065559857","2065553412",.....]

Upvotes: 0

Views: 36

Answers (2)

Guffa
Guffa

Reputation: 700252

You can use the map method to turn each object into an array containing the key and value, and then use the same method to concatenate all the arrays:

a = $.map(a, function(o){ return $.map(o, function(x, i){ return [x, i]; }); });

Demo: http://jsfiddle.net/Guffa/XV7yz/

Upvotes: 1

faerin
faerin

Reputation: 1925

What about...

var jsonString = [{"2065559857":"2065559482"},{"2065559857":"2065553412"},{"2065559857":"2065558122"}];    
var myArray = [];

for(var i in jsonString){
    myArray.push([i,jsonString[i]]);
    }

Or jQuery:

var jsonString = [{"2065559857":"2065559482"},{"2065559857":"2065553412"},{"2065559857":"2065558122"}];   
var myArray = [];

$.each(jsonString, function(key,value){
    myArray.push(value);
    });​

Upvotes: 0

Related Questions