0

I have the following statement:

const queue = [
  {name: "Click2Call"}
]
return queue.name

This returns null.

How can I fix it to return the object name?

1
  • queue is an array, you have to access the position before get the attribute. Commented Feb 3, 2021 at 19:10

2 Answers 2

1

What are you trying to do? This

queue:[{"name": "Click2Call"}]

is syntactically correct, but doesn't do anything. If you are trying to create a variable called queue you need to declare the variable with const or let (or var) and use the assignment operator =. For example:

const queue = [{"name": "Click2Call"}]

But this is also an array which doesn't have a name property. You need to access the first element of the array. For example:

return queue[0].name
Sign up to request clarification or add additional context in comments.

1 Comment

Tks man! I created constant and convert Object.assign, its worked! Tks!
0

You're trying to access an array with a key. You can try: return queue[0].name

But that is not robust and can fail if the array is empty or if the 0 indexed value doesn't have that key.

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.