skip to Main Content

Add up JSON strings to one variable | JavaScript

I have been trying to figure out how to merge several JSON strings into one. My method is this: if (observations[31]) { // Ignore this. document.getElementById("ajaxrainmo").textContent = observations[31].imperial.precipTotal + observations[30].imperial.precipTotal + observations[29].imperial.precipTotal + observations[28].imperial.precipTotal + observations[27].imperial.precipTotal + observations[26].imperial.precipTotal + observations[25].imperial.precipTotal…

VIEW QUESTION

Javascript – This code changing the image as expected but not the id?

const currentTypesResult=[{id:'155', foodId:'511555522559744444', image: 'Some image string', example:'example'}] const processedResults = currentTypesResult.map((item) => { const { foodId, image, ...rest } = item; return { id: '5542', image: 'data:image/png;base64,', ...rest }; }); console.log(processedResults[0].id) // Prints 155? Why? Why not 5542? console.log(processedResults[0].image)…

VIEW QUESTION
Back To Top
Search