1

So, here is the code which is using find helper in javaScript and supposed to return a value but instead of that it is showing undefined.

function Car(model) {
this.model = model;
}
var cars = {
 new Car('Buick'),
 new Car('Camaro'),
 new Car('Focus')
};
cars.find(function(car){
 return car.model === 'Focus';
});

I am running this code in VB and the output supposed to be Focus but it is showing undefined.

1 Answer 1

1

Your cars variable needs to be an array not an object as you don't have keys, just a list. Here is a working example:

function Car(model) {
  this.model = model;
}
var cars = [
  new Car('Buick'),
  new Car('Camaro'),
  new Car('Focus')
];
console.log(cars.find((car) => car.model === 'Focus'));

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.