Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript object duplicate keys

//It's not possible to have duplicate keys in a javascript object
const obj = {};
obj.a = 1;
obj.a = 2; //overrides the previous value of a in obj

console.log(obj.a) //prints 2

//If you want to use same key to store multiple values,
//store the values in an array inside obj
obj.key1.push("something");
obj.key1.push("something else");
console.log(obj.key1) //["something","something else"]
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript class is not defined 
Javascript :: how to implement useMemo inside react cntext api 
Javascript :: react-inline-script 
Javascript :: prisma.db firebase 
Javascript :: index wise print elemnet in javascript 
Javascript :: left join in javascript 
Javascript :: move_uploaded_file equivalent in js 
Javascript :: express docs 
Javascript :: double exclamation mark javascript 
Javascript :: regex for erlang online 
Javascript :: how to get multiple values from json array using jq 
Javascript :: onScrollBottom 
Javascript :: how to get a set of values in mogodb 
Javascript :: express check request type 
Javascript :: load content on user language in javascript 
Javascript :: Get the max value from array - divi modules 
Javascript :: react three fiber set cursor pointer 
Javascript :: how to put condition on pagination material table 
Javascript :: return the remainder from two numbers javascript 
Javascript :: Pointing Subdomain To A Next.js Page On Vercel 
Javascript :: javascript Scroll into a div that is hidden initially in react 
Javascript :: AngularJS ui-select multiple should show alert if limit is crossed 
Javascript :: How to set up path paramater in angular and access in the controller 
Javascript :: Check AngularJS checkbox with Selenium 
Javascript :: Context: Cannot read properties of undefined 
Javascript :: the given sign-in provider is disabled for this firebase project 
Javascript :: Node.js with Express: Importing client-side javascript using script tags in Jade views 
Javascript :: Using Bind() With BuiltIn JavaScript Function 
Javascript :: input json decode 
Javascript :: javascript object access time complexity 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =