I would like to ask you a question about the dict output in the javascript list.

Asked 2 years ago, Updated 2 years ago, 34 views

Hello,

There is data as below.

data = [{ 'a' : '1',  'b' : '2' ,  'c' : '3' } , { 'd' : '4', 'e' : '5', 'f' : '6' }, { 'g' : '7', 'h' : '8', 'i' : '9' }]

This

'a' : '1',  'b' : '2' ,  'c' : '3'

'd' : '4', 'e' : '5', 'f' : '6' 

'g' : '7', 'h' : '8', 'i' : '9' 

Is there a way to print it out in javascript like this?

javascript list

2022-09-20 22:08

1 Answers

var data = [
    { { 'a' : '1',  'b' : '2' ,  'c' : '3' },
    { { 'd' : '4', 'e' : '5', 'f' : '6' },
    { { 'g' : '7', 'h' : '8', 'i' : '9' }
];

// The data is an array of objects (corresponding to the dict of the Python) (corresponding to the list of Pythons).
// So if you go around the data...
data.forEach((obj) => {

    // ...You can do something with each object (corresponding to Python's dict).
    // Convert this to a JSON string and then...
    let str = JSON.stringify(obj);

    // Let's subtract the first "{" and the last "}" and print it out.
    console.log(str.substring(1, str.length - 1));
});


2022-09-20 22:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.