Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding key/value into array where value is a object

Adding key/value into array where value is a object

I want to add some text as a key and Object as a value.

Example

$('#clickme').on('click' , function() {
    push to array => "some_text" as (value) and $(this) as key
})
like image 430
user1184100 Avatar asked Dec 06 '25 20:12

user1184100


1 Answers

Just use a normal object which works as an associative array anyway:

var myObj = {};
$('#clickme').on('click' , function() {
    myObj["some_text"] = $(this);
});
like image 132
njr101 Avatar answered Dec 08 '25 09:12

njr101



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!