0

I am not experienced with javascript and sometimes it pulls out weird issues like this that I can't figure out even if I find on google solutions for what I want to do.

Doing this console logs:

console.log(this.data.proSkills);
console.log(this.data['proSkills']);

This is the result:

{id: "xhg6jdfKRdjl1OHGIqwT", proSkills: Array(2)}
{id: "xhg6jdfKRdjl1OHGIqwT", proSkills: Array(2)}

Intellisense is giving me extentions methods/properties like forEach and length but they are all undefined.

console.log(this.data['proSkills'].length);

this.data.proSkills.forEach(f => {
  console.log(f);
})

Result:

undefined
[sm]:1 ERROR TypeError: this.data.proSkills.forEach is not a function

This is how the full object looks like:

{id: "xhg6jdfKRdjl1OHGIqwT", proSkills: Array(2)}
      id: "xhg6jdfKRdjl1OHGIqwT"
      proSkills: Array(2)
         0:
            name: "ffffff"
            __proto__: Object
        ...

I am trying to update an array to firebase, if length is greater than 0 then populate the reactive form with the array and update if length is 0 then just add values, this is all I want to do but I can't access the inside array since length is undefined and I can't even get to print the array in the console because it shows the whole object anyways.

1
  • 1
    Where does that object come from, and what is the relationship between that context and the point in your code where you attempt to console.log() the contents? Commented Sep 22, 2020 at 11:47

2 Answers 2

4

Note that console.log(this.data.proSkills) is logging an object:

{id: "xhg6jdfKRdjl1OHGIqwT", proSkills: Array(2)}

That object has a property proSkills that is an array. So it should be

this.data.proSkills.proSkills.forEach(someCallbackFn);
Sign up to request clarification or add additional context in comments.

Comments

2

Your data has an id and the array proSkills, add another .proSkills like this:

this.data.proSkills.proSkills.forEach(...)

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.