Skip to main content
52 votes
2 answers
31k views

The new method Object.hasOwn() returns a boolean indicating whether the specified object has the indicated property as its own property but so does Object.prototype.hasOwnProperty(), what is the ...
1 vote
1 answer
141 views

I'm building my first framework. I need to be able to generate a semi-dynamic object, to which end, I want to re-use a single variable that points to a unique-value-returning function. I have a JS ...
154 votes
7 answers
247k views

Is there a way to get (from somewhere) the number of elements in a Javascript object?? (i.e. constant-time complexity). I can't find a property or method that retrieves that information. So far I can ...
5009 votes
64 answers
3.7m views

What is the most concise and efficient way to find out if a JavaScript array contains a value? This is the only way I know to do it: function contains(a, obj) { for (var i = 0; i < a.length; i++...
-7 votes
1 answer
191 views

I have an object obj; and I then obtain an array arr of key-value pairs. Assuming that the key sets of obj and of arr are disjoint (i.e. no key appears in both) - how do I efficiently add all pairs in ...
40 votes
7 answers
26k views

Are arrays merely objects in disguise? Why/why not? In what way(s) are they (such/not)? I have always thought of arrays and objects in JS as essentially the same, primarily because accessing them is ...
25 votes
2 answers
2k views

In JavaScript, when you do something like this, function connect() { var ws = new WebSocket(url); ws.onmessage = function(e) { window.alert(e.data); }; } it will work. But why ...
1 vote
2 answers
2k views

I am tryin to get some info from PeopleManager.getMyProperties() function. I get the object,some values are null.when i check it from User Profile from Management,I can see the value. How can i fix ...
0 votes
1 answer
163 views

I am trying to merge statics and prototypes of several classes in to 1 masterclass like in the example below. Is that actually possible? My goal is that im able to merge the statics and prototypes to ...
2 votes
3 answers
234 views

When considering this simple example <script> function test() { this.x = 10; } var obj = new test(); </script> I read in on one of the blogs that when we use a new keyword , a ...
1 vote
3 answers
99 views

I am quoting this statement from the JavaScript Definitive Guide book in section 6.1.4 Object.create(). The following statement doesn't seem clear to me. You can pass null to create a new object ...
3 votes
4 answers
7k views

I am trying to custom sort a JavaScript object but not able to get how we can do this in a right way. Say I am having an object like var test = { 'yellow': [], 'green': [], 'red': [], 'blue': ...
7 votes
3 answers
5k views

My javascript object looks like this: const someObj = { arr1: ["str1", "str2"], arr2: ["str3", "str4"] } In attempting to rename a key (e.g. arr1), I end up deleting the existing key and writing ...
1 vote
2 answers
5k views

I get the following error: Uncaught TypeError: Cannot convert undefined or null to object at Function.keys (<anonymous>) Relevant code (used in a React project): const transformedIngredients = ...
1 vote
1 answer
103 views

I’m working on a WordPress website using the Elementor Pro page builder, and I’m trying to integrate a custom-styled Google Map on the "Contact Us" page. What I’ve done so far: Created a ...

15 30 50 per page
1
2 3 4 5
479