Bruno Laise
Bruno Laise

Reputation: 117

how can I remove quotes from array

 $.getJSON('data.json', function(data) {
        var arr = [];

        for(var i = 0, j = data.length; i < j; i++)
        {
            var param = data[i];

            if(param['p'] == 'levelA')
            {
            arr.push('{"x":'+param['t']+','+'"y":0'+','+'"h":'+param['v']+','+'"w":1,'+'"bg":"magenta"}');
            }   
        }
    })

this code return

["{"x":5.07527,"y":0,"h":0,"w":1,"bg":"magenta"}", "{"x":5.08601,"y":0,"h":7,"w":1,"bg":"magenta"}", "{"x":5.09164,"y":0,"h":12,"w":1,"bg":"magenta"}", "{"x":5.10255,"y":0,"h":19,"w":1,"bg":"magenta"}", "{"x":5.11356,"y":0,"h":26,"w":1,"bg":"magenta"}"....

I need remover "", transforme this

"{"x":5.07527,"y":0,"h":0,"w":1,"bg":"magenta"}"

to {"x":5.07527,"y":0,"h":0,"w":1,"bg":"magenta"}

Upvotes: 0

Views: 120

Answers (1)

Barmar
Barmar

Reputation: 780939

Don't push a string into arr, push an object:

arr.push({ x: param.t, y: 0, h: param.v, w: 1, bg: "magenta" });

Upvotes: 2

Related Questions