Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

check if an object contains a value in javascript

var obj = { a: 'test1', b: 'test2' };
if (Object.values(obj).indexOf('test1') > -1) {
   console.log('has test1');
}
Comment

check if object has method javascript

if(typeof myObj.prop2 === 'function') {
    alert("It's a function");
} else if (typeof myObj.prop2 === 'undefined') {
    alert("It's undefined");
} else {
    alert("It's neither undefined nor a function. It's a " + typeof myObj.prop2);
}
Comment

js does object contain value

// You can turn the values of an Object into an array.
// Then test that a value is present:

// This assumes, that the Object is not nested
// and the value is an exact match:

var obj = { a: 'test1', b: 'test2' };

// Note that an array can only have positive index's; so
// checking for a negative index is a super valid way for getting a
// boolean value as a result for the check.
if (Object.values(obj).indexOf('test1') > -1) {
   console.log('Value exists!');
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: active menu adminlte 3 using jquery 
Javascript :: javascript on url anchor change event 
Javascript :: conditinally object property js 
Javascript :: two button in one row react native 
Javascript :: loop json 
Javascript :: next js active link 
Javascript :: get x characters from string javascript 
Javascript :: add array to localstorage 
Javascript :: js json download 
Javascript :: ajax post 
Javascript :: discord js delete message after time 
Javascript :: send message to all servers discord.js 
Javascript :: chart js rotating the x axis labels 
Javascript :: aos library animation angular 
Javascript :: express js example 
Javascript :: elixir file open and parse json 
Javascript :: alpinejs cdn 
Javascript :: javascript init an array to 0 
Javascript :: javascript remove space from string 
Javascript :: how to store words in an array in javascript 
Javascript :: js deep copy array 
Javascript :: change font js 
Javascript :: get last part of url jquery 
Javascript :: exceljs column pick from drop down list 
Javascript :: alert ok with link 
Javascript :: short date angular pipe 
Javascript :: javascript set div height 
Javascript :: js array value that appears odd number of times 
Javascript :: how to extend a type in jsdoc 
Javascript :: jquery set multiple css properties 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =