1

Here is the code I am using in a larger function:

this.categoriesToSearch = ko.observableArray(["Food"]);// Initial selection
console.log(this.categoriesToSearch[0]);

Running this returns undefined. Knockout.js documentation says observableArrays are supposed to be read that way. Is there a better way to read observableArrays?

0

2 Answers 2

1

Answering my own question since I came up with the answer right after posting: observableArrays are functions so the correct way to pull an item is:

this.categoriesToSearch()[0]
Sign up to request clarification or add additional context in comments.

Comments

0

Try this.categoriesToSearch()[0]

KO documentation says you have to handle observable array like a function call.

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.