0

i have below object structure like as in below image and i am trying to match with the inner object property(like massing type id) with the existing ID and if it is match i need to get the name of that object and push it to array and set that array in state object,

enter image description here

and the code is looks like as below

    Object.values(constructionSets).forEach(item => {
        console.log(item);
        const constructionSetItem = [];
        if (
          item.ashraeClimateZone?.id === ashraeClimateZoneId &&
          item.massingType?.id === massingTypeId &&
          item.sourceOfData?.id === energyCodeId
        ) {
          setConstruction(constructionSetItem.push(item.name));
        }
      });

and when i log item i am getting array of objects instead of single object, could any one please let me know where i am doing wrong with the above code?

thanks in advance.

3
  • 1
    Can you post the constructionSets value passed into .values()? Commented Oct 7, 2020 at 22:37
  • constructionSets appears is already an array, so Object.values(constructionSets) should return back an identical array and the console.log(item); is log of each object. Commented Oct 7, 2020 at 22:39
  • @mmason33 that is just array of 4 Commented Oct 7, 2020 at 22:40

1 Answer 1

1

From what I see in the information you gave, that constructionSets variable is already an Array so to loop it, you just need to do:

constructionSets.forEach(item => {...})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.