[SalesForce] JS method is returning the value as undefined after assignment in LWC

Here is the snippet of my code

@track alltraffic = [];

//using wire method to call a method to load all values while page load
@wire(getAllTraffic) alltraffic;

//calling different method with parameters imperatively and assigning to 
 this.weekend = event.target.value;

getSpecificTraffic({divId: this.divisionvalue, communityId: 
                     this.communityvalue, week: this.weekend})
    .then(result => {
    this.alltraffic = [...result].map(record => {return record});   

    .catch(error => {
        this.error = error;

when i do JSON.Stringify, i get the result in console.log but i wanted that as data format, so i can show that in my table.

i get the table value in the wire method, but i am calling another method imperatively that updates the same JS variable to display the data, but i am not getting it as data. I get as [object Object] and if i stringfy it is in JSON format. How can i get it as data.

in the wire method i am using alltraffic and use alltraffic.data in the html.

here is my HTML code

<template if:true={alltraffic.data}>   
   <tbody >
         <template for:each={alltraffic.data} for:item="traffic">
              <div class="slds-truncate"> {traffic.trafficType} </div>


Best Answer

If you parse it back into an object JavaScript reads it as primitive object again

let data = JSON.parse(JSON.stringify(result));
Related Topic