0

I need a help! I have a json object like this: (res.json(record[0].content)) I need to transform this json to another view... Select only some values... I would be grateful for any help!

[
    {
        "classId": 0,
        "type": "d",
        "cluster": -2,
        "position": 1,
        "version": 0,
        "value": {
            "@type": "d",
            "rid": "#15:0",
            "class": "Currency",
            "Name_currency": "Фунт"
        }
    },
    {
        "classId": 0,
        "type": "d",
        "cluster": -2,
        "position": 2,
        "version": 0,
        "value": {
            "@type": "d",
            "rid": "#15:1",
            "class": "Currency",
            "Name_currency": "Доллар"
        }
    },
    {
        "classId": 0,
        "type": "d",
        "cluster": -2,
        "position": 3,
        "version": 0,
        "value": {
            "@type": "d",
            "rid": "#15:2",
            "class": "Currency",
            "Name_currency": "Гривна"
        }
    }
]

How can I get this? Only values of my json object?

[
    {
        "@type": "d",
        "rid": "#15:0",
        "class": "Currency",
        "Name_currency": "Фунт"\
    },
    {
        "@type": "d",
        "rid": "#15:1",
        "class": "Currency",
        "Name_currency": "Доллар"
    },
    {
        "@type": "d",
        "rid": "#15:2",
        "class": "Currency",
        "Name_currency": "Гривна"
    }
]
3
  • 4
    Show us your efforts, no one can code for you.. Commented Jun 25, 2014 at 10:11
  • Is res.json a function of some kind? Commented Jun 25, 2014 at 10:16
  • 1
    @Andy It is part of Express.js callback for request. Commented Jun 25, 2014 at 10:17

3 Answers 3

1

Use Array.prototype.map on your backend (Node.js) site:

res.json(record[0].content.map(function(e) {
    return e.value;
}));
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! I tried to sort out and rewrite all the new array. Thank you again!)
1

You should use javascript map() method (where a is your first array):

var newObj = a.map(function(obj){
    return obj.value;
});

console.log(newObj);

For more information https://developer.mozilla.org/ru/docs/JavaScript/Reference/Global_Objects/Array/map

Comments

0

use .each() in jquery to traverse the object

var value=[];
$.each(data,function(i,val){   
  value.push(val.value);  
});

console.log(value);

DEMO

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.