Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Commonmark migration
Source Link

The Underscore js Way

##The Underscore js Way WhichWhich is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects.

###Solution:

Solution:

var data = {
 code: 42,
 items: [{
 id: 1,
 name: 'foo'
 }, {
 id: 2,
 name: 'bar'
 }]
};
var item = _.findWhere(data.items, {
 id: 2
});
if (!_.isUndefined(item)) {
 console.log('NAME =>', item.name);
}
//using find - 
var item = _.find(data.items, function(item) {
 return item.id === 2;
});
if (!_.isUndefined(item)) {
 console.log('NAME =>', item.name);
}

##The Underscore js Way Which is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects.

###Solution:

var data = {
 code: 42,
 items: [{
 id: 1,
 name: 'foo'
 }, {
 id: 2,
 name: 'bar'
 }]
};
var item = _.findWhere(data.items, {
 id: 2
});
if (!_.isUndefined(item)) {
 console.log('NAME =>', item.name);
}
//using find - 
var item = _.find(data.items, function(item) {
 return item.id === 2;
});
if (!_.isUndefined(item)) {
 console.log('NAME =>', item.name);
}

The Underscore js Way

Which is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects.

Solution:

var data = {
 code: 42,
 items: [{
 id: 1,
 name: 'foo'
 }, {
 id: 2,
 name: 'bar'
 }]
};
var item = _.findWhere(data.items, {
 id: 2
});
if (!_.isUndefined(item)) {
 console.log('NAME =>', item.name);
}
//using find - 
var item = _.find(data.items, function(item) {
 return item.id === 2;
});
if (!_.isUndefined(item)) {
 console.log('NAME =>', item.name);
}
added 174 characters in body
Source Link
Mohan Dere
  • 4.6k
  • 1
  • 28
  • 22

##The Underscore js Way Which is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects.

###Solution:

var data = {
 code: 42,
 items: [{
 id: 1,
 name: 'foo'
 }, {
 id: 2,
 name: 'bar'
 }]
};
var item = _.findWhere(data.items, {
 id: 2
});
if (!_.isUndefined(item)) {
 console.log('NAME =>', item.name);
}
//using find - 
var item = _.find(data.items, function(item) {
 return item.id === 2;
});
if (!_.isUndefined(item)) {
 console.log('NAME =>', item.name);
}

##The Underscore js Way Which is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects.

###Solution:

var data = {
 code: 42,
 items: [{
 id: 1,
 name: 'foo'
 }, {
 id: 2,
 name: 'bar'
 }]
};
var item = _.findWhere(data.items, {
 id: 2
});
if (!_.isUndefined(item)) {
 console.log('NAME =>', item.name);
}

##The Underscore js Way Which is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects.

###Solution:

var data = {
 code: 42,
 items: [{
 id: 1,
 name: 'foo'
 }, {
 id: 2,
 name: 'bar'
 }]
};
var item = _.findWhere(data.items, {
 id: 2
});
if (!_.isUndefined(item)) {
 console.log('NAME =>', item.name);
}
//using find - 
var item = _.find(data.items, function(item) {
 return item.id === 2;
});
if (!_.isUndefined(item)) {
 console.log('NAME =>', item.name);
}
Source Link
Mohan Dere
  • 4.6k
  • 1
  • 28
  • 22

##The Underscore js Way Which is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects.

###Solution:

var data = {
 code: 42,
 items: [{
 id: 1,
 name: 'foo'
 }, {
 id: 2,
 name: 'bar'
 }]
};
var item = _.findWhere(data.items, {
 id: 2
});
if (!_.isUndefined(item)) {
 console.log('NAME =>', item.name);
}
lang-js

AltStyle によって変換されたページ (->オリジナル) /