7,172 questions
52
votes
2
answers
31k
views
Object.hasOwn() vs Object.prototype.hasOwnProperty()
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
Are dynamic property tags in JS object literals possible?
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
Number of elements in a javascript object
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
How do I check if an array includes a value in JavaScript?
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
How should I efficiently add all pairs in a key-value array to an object?
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 Javascript arrays primitives? Strings? Objects?
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
Why do JavaScript Websocket objects not get destroyed when they go out of scope?
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
SharePoint userProfileProperties JSOM (JavaScript Object Model)
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
Is it possible to achieve multiple inheritance with ES6 classes?
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
__proto__ object in javascript
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
If an object created by `Object.create(null)` is supposed to lack methods, why can I invoke methods on properties I later add to it?
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
How can we custom sort JavaScript object keys?
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
JS rename an object key, while preserving its position in the object
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
Uncaught TypeError: Cannot convert undefined or null to object at Function.keys (<anonymous>)
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
Google Maps Custom Style Not Applying in WordPress (Elementor)
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 ...