in Education by
I have the following code: let pa = 0; let pw = 0; let pc = 0; let pi = 0; let pr = 0; this.state.array.data.map((i) => { if (i.mdn === this.queryParams.mdn && i.sources != null) { return (i.sources.map((sources) => { if (sources.source.toString().toLowerCase() === "a") { pa = sources.t.sessions.u } if (sources.source.toString().toLowerCase() === "w") { pw = sources.t.sessions.u } if (sources.source.toString().toLowerCase() === "c") { pc = sources.t.sessions.u } if (sources.source.toString().toLowerCase() === "i") { pi = sources.t.sessions.u } if (sources.source.toString().toLowerCase() === "r") { pr = sources.t.sessions.u } })) } }, this.setState({ web: [], app: [], preference: [{a: pa}, {w: pw}, {c: pc}, {i: pi}, {r: pr}] }), Once I get to set state, it doesn't actually set it, it just takes the 0 and throw throws in there. 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
Instead of using Array.prototype.map, try Array.prototype.forEach and set a preference object by key. To preserve the order of the keys, create an array of your desired order. let order = [ 'a', 'w', 'c', 'i', 'r' ]; preference = { a : 0, w : 0, c : 0, i : 0, r : 0 }; this.state.array.data.forEach((item) => { if (item.mdn === this.queryParams.mdn && item.sources != null) { return item.sources.forEach((entry) => { var key = entry.source.toString().toLowerCase(); preference[key] = entry.t.sessions.u; }); } }); this.setState({ web: [], app: [], preference: order.map(key => ({ [key] : preference[key] })); }),

Related questions

0 votes
    I have the following code: let pa = 0; let pw = 0; let pc = 0; let pi = 0; let ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    I have the following code: let pa = 0; let pw = 0; let pc = 0; let pi = 0; let ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    hello I have the following code that maps through my text and prints typography, {['Example1:', 'Example2 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    hello I have the following code that maps through my text and prints typography, {['Example1:', 'Example2 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    Multiple variables can be created and initialized in a single JavaScript statement 1. False 2. True...
asked Feb 23, 2021 by JackTerrance
0 votes
    What is true about variables 1. 7Wonders is a valid variable name to give 2. % is a valid first character for ... Variables are case sensitive 4. ^US is a valid variable name...
asked Feb 23, 2021 by JackTerrance
0 votes
    I'm using TensorFlow Alpha 2.0. I have TFRecords files I'm reading from, each one holding a short ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I've created a getSpectrum method using the getByteFrequencyData method on the Web Audio API's Analyser Node ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 27, 2022 in Education by JackTerrance
0 votes
    I have a custom input validation component that I use in a form. Something like 15 instances of this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I'm importing Popup from react-leaflet import { Marker, Map, Popup, TileLayer, ZoomControl, GeoJSON, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    I am using this codepen https://codepen.io/anon/pen/jJXmpZ but I am struggling to implement a new ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    I am using this codepen https://codepen.io/anon/pen/jJXmpZ but I am struggling to implement a new ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I created an list. When you select each , there will be active classes each. Now, my goal is how ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I have function of "endgame" and here's how the function goes function endgame() { setScreen("scorescreen" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 6, 2022 in Education by JackTerrance
0 votes
    I have created a partial view, the element in the partial view looks like this (Razor Code): @Html ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
...