in Education by
This is my object. values : { title : 'this is title ..', translate : { en : 'some texts .. ', }, } And this is array I have. arr = ['translate.en', 'title']; What I want to do is this, but this is not work as I expected. const value = arr.map(item => values[item]); // (Result) value : undefined, 'this is title ..' // (Expected) value : 'some texts .. ', 'this is title ..' const value = arr.map(item => values.item); // error : 'item' is declared but its value is never read. How to get values.translate.en value using map()? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
you can use this snippet. Not the cleanest, but you get the idea arr.map(item => { let arrItem = item.split('.'); let data = values; for (i in arrItem) { data = data[arrItem[i]]; } return data; });

Related questions

0 votes
    This is my object. values : { title : 'this is title ..', translate : { en : 'some texts ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 3, 2022 in Education by JackTerrance
0 votes
    i have an array of objects in [ { "country": "USA", "payment": [ { "paymentType": "Visa" ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 6, 2022 in Education by JackTerrance
0 votes
    I'm a bit surprised I'm having trouble finding this online, but I can't seem to find an example ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I'm a bit surprised I'm having trouble finding this online, but I can't seem to find an example ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I'm a bit surprised I'm having trouble finding this online, but I can't seem to find an example ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I am trying to calculate the progress of a file upload, so I was using Superagent. I was able to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    Hi I have to pass array as props to a functional component. Show code snippet But it is converted ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Hi I have to pass array as props to a functional component. Show code snippet But it is converted ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    Hi I have to pass array as props to a functional component. Show code snippet But it is converted ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: useState set method not reflecting change immediately (17 answers) Closed ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: useState set method not reflecting change immediately (17 answers) Closed ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I was unable to find a solution that is identical with the issue I am trying to solve. If is a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I was unable to find a solution that is identical with the issue I am trying to solve. If is a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I try to merge some object into one array I did output by q = [["99","99","99"],["9" ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    I'm trying to use createCriteria with OR on two nested objects. This is the code I'm working with ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
...