Accessing nested JavaScript objects and arrays by string path

0 votes

This is my data structure

var someObject = {
    'part1' : {
        'name': 'Part 1',
        'size': '20',
        'qty' : '50'
    },
    'part2' : {
        'name': 'Part 2',
        'size': '15',
        'qty' : '60'
    },
    'part3' : [
        {
            'name': 'Part 3A',
            'size': '10',
            'qty' : '20'
        }, {
            'name': 'Part 3B',
            'size': '5',
            'qty' : '20'
        }, {
            'name': 'Part 3C',
            'size': '7.5',
            'qty' : '20'
        }
    ]
};

I want accessibility in this using this structure

var part1name = "part1.name";
var part2quantity = "part2.qty";
var part3name1 = "part3[0].name";

The value of someObject.part1.name, which is "Part 1," should be used as part1name. The part2quantity, which was filled with 60, is the same.

Is it possible to accomplish this with JQuery or just pure Javascript?

Aug 8, 2022 in Others by krishna
• 2,820 points
494 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

0 votes
1 answer
0 votes
0 answers

Can we write AES enryption in Javascript and Decryption in Java using a static SALT and IV

I'm working on AES encryption I want to ...READ MORE

Jun 4, 2019 in Others by Eighteen
• 120 points
1,887 views
0 votes
1 answer

can somebody explain me what does "passing by value" and "Passing by reference" mean in C#?

To answer your question, “passing by value” ...READ MORE

answered Feb 10, 2022 in Others by Rahul
• 9,680 points
781 views
0 votes
0 answers

What is DynamoDB number and string data type storage space

What is the storage space for a ...READ MORE

Apr 5, 2022 in Others by Kichu
• 19,040 points
816 views
0 votes
0 answers
0 votes
1 answer

Presenting docket dtates inside html page by javascript

Use the Docker Engine Api:Docker Engine API ...READ MORE

answered Jun 20, 2018 in Docker by DareDev
• 6,890 points
729 views
0 votes
1 answer

Migrating proxy npm repo in nexus 3

I don't think you can achieve this ...READ MORE

answered Jun 22, 2018 in DevOps Tools by DareDev
• 6,890 points
1,518 views
+1 vote
1 answer

What is the difference between JavaScript and Java

This quote rightly explains that 2 totally ...READ MORE

answered Jun 29, 2018 in Java by Daisy
• 8,140 points
784 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP