Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get object key from value javascript

const key = Object.keys(obj).find(key => obj[key] === value);
Comment

how to get key from value in javascript

function getKeyByValue(object, value) {
  return Object.keys(object).find(key => object[key] === value);
}


const map = {"first" : "1", "second" : "2"};
console.log(getKeyByValue(map,"2"));
 Run code snippetHide results
Comment

get key for value javascript

const findingKey = (obj , value) => (Object.keys(obj).find(key => value === obj[key]))
console.log(findingKey({id:"123",name:"Alice"},"Alice");
Comment

PREVIOUS NEXT
Code Example
Javascript :: useScroll 
Javascript :: uppercase-the-first-letter-of-a-string-using-javascript/ 
Javascript :: how to add items to object in javascript 
Javascript :: axios data fetch 
Javascript :: for in loop js 
Javascript :: js date to timestamp 
Javascript :: vuejs transform observer to object 
Javascript :: js detect if content editable div is empty 
Javascript :: NaN 
Javascript :: how to set default value in input field in angularjs 
Javascript :: javascript array read object value in array 
Javascript :: how to pass a prop in route 
Javascript :: vue 3 create app 
Javascript :: how to remove the desimal numbers in javascript 
Javascript :: upgrading to react 18 
Javascript :: prevstate in react 
Javascript :: react native gif dont work 
Javascript :: object.keys mdn 
Javascript :: disabled text color tailwind 
Javascript :: Find duplicate or repeat elements in js array 
Javascript :: on scroll call function jquery 
Javascript :: remove the first item from an array 
Javascript :: Get the current tab 
Javascript :: appendchild javascript 
Javascript :: getting data from an api 
Javascript :: nextjs react native web typescript 
Javascript :: change color react icon 
Javascript :: Angular empty object 
Javascript :: html get form elements 
Javascript :: using arrow function and destructuring 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =