7,178 questions
-6
votes
1
answer
148
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 ...
24
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
1
answer
68
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 ...
-1
votes
1
answer
87
views
How do I declare a function async in a JavaScript object literal/initialiser?
I'd like to have the loadConfig function async and just finish after the resource has been loaded. await fetchetc. How can I declare it in this object syntax as an async function?
var QMEM = QMEM || {
...
0
votes
0
answers
132
views
Issue with Injecting Text into WhatsApp Web Input via JavaScript Extension
I'm working on a JavaScript extension for WhatsApp Web, and I'm facing a problem I can't seem to solve. The goal of my extension is to correct and manipulate the text in the message input of WhatsApp ...
0
votes
0
answers
43
views
Why does offsetHeight log an increased height when called from object than what is shown in the object log itself?
I have an object taken from the DOM who's actual offsetHeight I can not correctly get.
When trying to console.log the object to check the property, it does show the correct offsetHeight. But when I ...
0
votes
0
answers
27
views
Storing an object key/value in an array but not in an array element [duplicate]
I found some odd things and am looking for explanations as to how and why
let a = [] ;
a.push({foo:"bar",bar:"foo"}] ;
console.log(a) ;
As expected, prints out:
[[object Object] {
...
0
votes
0
answers
24
views
What's the difference between setting object properties recursively and Object.assign? [duplicate]
So I wrote up this helper function when I first started my project to help update objects that I would get from an API.
export const setValRecursive = (currObj: any, newObj: any) => {
Object.keys(...
-1
votes
1
answer
67
views
Question about Javascript: Can I assign two names to the same member? [closed]
I have a set of objects, that contain references to other objects. There is always a general reference: nextObject. But sometimes, I know more about the object beside me. So I could use a member ...
0
votes
1
answer
45
views
Intantiating a Javascript extended class from Array with only one element
I am implementing an extended class from Array with numerical methods such as sum, mean, std, etc.
There is no problem to instantiate an object with zero or 2+ elements, but I can't implement one-...
-5
votes
1
answer
112
views
Javascript cannot map object with repetative values
I need to style specific elements by id using given object.
Keys and values in projectSkillsMap object corresponds to ids in html file. When user clicks on element with id listed in object keys ...
-5
votes
1
answer
94
views
Initiate all potential props of the object right away or as you go? [closed]
I'm my scenario I have to create a lot of objects (100k+). Those objects can 'evolve' in the course if their life. Some will stay practically unchanged, others with will mutate and have a bunch of ...
0
votes
1
answer
72
views
How to retrieve the name of an Object passed as a Key to a Map?
I'm a newbie to Javascript. I wish to know how to get the key as 'personObj', 'carObj, 'workDetailsObj', 'displayFunction' and 'primitiveValue' and print those values in console? Also, how to print ...
0
votes
1
answer
25
views
Merge the 2 array based on id and prioritize the latest filtered on top
const menuFilteredProducts = getMenuWiseProduct(products);
const categoryFilteredProducts = getCategoryWiseProduct(products);
let mergedProducts = [];
const prioritizeCategory = true;
if (...
5
votes
1
answer
270
views
What is a restricted JavaScript object?
I'm trying to use custom DOM events to communicate between the main world and the isolated world for a page in a webextension in Firefox. When trying to access an event object property, I get an ...
0
votes
1
answer
64
views
Why do I get a property assignment error while using script tags on HTML
I am practicing fetching API data and displaying it on a web page. I am using Go to fetch quotes data from an API service. I want an additional slideshow functionality for the web page that should ...
0
votes
0
answers
106
views
Why does the GeoJSON format expect coordinates in an array rather than an object with keys?
Take the following example from their home page:
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]...
3
votes
3
answers
79
views
Convert key value object to array of objects
I have object key value in below format.
{
"Code1": {
"char10": "ch1",
"number1": "1",
"text1": "txt1"
...
0
votes
0
answers
66
views
display button into html form failed with initialize
My script doesn’t work well.
When the button “b5” clicked with ouside <form ...> ... element, the buttons b5 and b4 deseapper and the buttons b1,b2,b3 appear. This work normaly when my code ...
0
votes
1
answer
58
views
How can I count how many times a function argument has been used in JS?
I need to construct a function, which takes a black-box one-argument function as an argument. And I need to know, how many times the black-box function uses its argument
Example signature:
function ...
-1
votes
1
answer
131
views
JS manipulates the DOM, then CSS doesn't load properly on refresh, even though cache is disabled [closed]
PROBLEM
Hi, I have some JS that manipulates the DOM to show / hide certain elements when needed. It works perfectly when the event handler is fired (click event). The problem is that when I refresh ...
0
votes
3
answers
117
views
Using hasOwnProperty for nested object keys if key name is a number
I'm currently building a Pokémon application, therefor I'm accessing data from PokéAPI and will store specific data in a variable, such as name, id and type.
Currently I'm facing issues to store the ...
1
vote
0
answers
36
views
How to retain scrollbar position even after reloading using javascript
After clicking on any lower check box in the grid the vertical scrollbar position changed to top level in the grid. How to keep the vertical scrollbar in same position after reloading the grid.?
after ...
-2
votes
1
answer
38
views
how do i manipulate my object with its own properties [duplicate]
Currently learning JS, im a beginner.
I created an object to tinker with, and i want to give it some properties that are dependent on th previous properties of the same object.
I have managed to solve ...
0
votes
0
answers
14
views
Google Sheet - Image as button
I would like to use an image as a button for me to go to another cell in the same sheet. Happy if I can get someone to share the appropriate scripts. Thanks
I have tried a button to go to another ...
0
votes
2
answers
39
views
How Do I Get Data from JSON Format in Javascript
I've been struggling with how to retrieve data from a JSON structured response to a query of a Sony Bravia TV. I've tried SEVERAL syntax variations to get just a single element's data, but no joy.
...
0
votes
0
answers
37
views
how to click cq-toggle element dynamically using javascript
how to click cq-toggle element dynamically using javascript?
When i click manually on cq-toggle menu item it actually adds active class to the element cq-toggle and add one div content in document ...
0
votes
0
answers
64
views
Create "path" to "dotted" variable such as "a.b.c.d.e.f" [duplicate]
It is simple to create a variable such as "a", but as soon as I want to create "a.b", I need to know that "a" exists first, I'm trying to create a function such as "...
0
votes
2
answers
82
views
Add up JSON strings to one variable | JavaScript [duplicate]
I have been trying to figure out how to merge several JSON strings into one.
My method is this:
if (observations[31]) { // Ignore this.
document.getElementById("ajaxrainmo").textContent = ...
0
votes
2
answers
63
views
merge javascript objects in array
I'm trying to merge an array of object by removing the ones which have the same code attribute and computing its times attribute.
given the following array:
let itemsTimes = [
{
item: {
...
1
vote
0
answers
276
views
document.querySelector() returns null for an existing element
I have issues selecting certain elements on a specific web page, querySelector returns null unless I first go through one of the parent element.
I tried chaining them together but still I eventually ...
-1
votes
2
answers
74
views
Compare two array of objects and push or pop objects from first array based on second array
consider below 2 array of objects, say arr1 and arr2.
based on id, if any new item exist in arr2 copy item to arr1 and remove item from arr1 if that item not present in arr2.
Tried something like this,...
-2
votes
1
answer
24
views
How to extract and insert json data in a key and value format
I have this data and would like to extract the Title data only and insert it as a id and value.
const dataSource = [
{
id: '1',
Title: 'My World',
Price: 10,
},
{
id: '2',
Title: 'My Home',
Price: 20,
...
1
vote
0
answers
51
views
JavaScript Module Object Cannot be Identified, Resulting in this Error: "TypeError: Cannot read properties of undefined (reading 'getNodeItem')"
As a preface for my question, I am very new to JavaScript and come from a strongly-typed language background (e.g. Java and C++). Although I have prior experience with JavaScript, I am not entirely ...
0
votes
1
answer
59
views
Why is the below piece of code giving error when I add console log line and working fine if I remove it?
The code below works fine if I remove the console log line but not with it
function gcd(a, b) {
while (b !== 0) {
console.log(a,b)
[a, b] = [b, a % b];
}
return a;
}
...
1
vote
2
answers
169
views
Why is reading the length property of a string in JavaScript O(1) and not O(n)
Strings are primitives, meaning they don't actually have methods or properties associated with them. According to MDN
In contexts where a method is to be invoked on a primitive string or a property ...
0
votes
1
answer
63
views
How do I access dynamically created objects and their properties in JavaScript?
If I write a function that creates a new person and attach it to an onClick event on a button, how can I access the data that was entered without a variable name?
When a user presses the button, the ...
1
vote
0
answers
35
views
proxy for 3d array, knowing the two indexes of array inside the handler function
I have this JavaScript Proxy code which I want to trigger the set handler that can tell me the first and second keys.
This means that when I try to set globalVar.a.b = "55b" only the line ...
1
vote
0
answers
27
views
Why does the name of a property change what access method works?
I have an object named facility
facility = {
facility_id: 495867,
facility_name: "4 Pig farms Brookvale",
registered_business_name: "BROOKVALE FARMS COMPANY PTY LTD",
...
0
votes
4
answers
74
views
get total of empty values in an object
please I need help with this
const obj = {a="", b="good", c=false, d="", e="excellent"}
I just want to know total empty and false. where my answer is suppose ...
0
votes
1
answer
73
views
Inserting Javascript array elements into another array with ternary operator
I have an array of objects where each object defines a field in a React form. I want to display different sequence of fields depending on a boolean state. This means that I need to insert either one ...
0
votes
2
answers
64
views
How do I check if a the mouse has touched a Javascript object that is randomly generated?
I am attempting to create a game where objects (currently circles) are randomly generated within a canvas, and the objects and their positions (plus other info) are stored within an array.
The objects ...
-1
votes
1
answer
41
views
Add Object name and Variable Name using Javascript [duplicate]
I Have A Object Called res and i have a variable Called lea
need to concatenate
for example
let lea = "abc";
let res = {
abc:'steve'
};
console.log(res.lea);
So My Output Should Be steve
I ...
0
votes
2
answers
100
views
How can I generate a new name for a new object and then add it to an array
I need to write a function that returns an array of objects.
The function will select the winners based on two factors: how much they paid, and their seat number. If both of these numbers are odd, the ...
0
votes
1
answer
200
views
Office script to get data from table, filtered data and pasted into a new tab and new table
I have been trying to extract filtered data from my "PMs" table in my excel, I need to filter column D for statuses that are equal to "WSCH" or "WAPPR" or "INPRG&...
0
votes
1
answer
19
views
how to convert htlm language to app languge
How to convert HTML language to APP language
I tried to convert IN VS Code. It did not work. VS code is text editor and VS Code doesnot support app language. Donot tried in other text editor. This ...
1
vote
1
answer
40
views
Object array type property is undefined in different file
I am in the process of refactoring a js file in which I used the THREE.js library to draw a truck visualization based on the parameters provided in the form. The code worked, but I need to extend it ...
1
vote
2
answers
75
views
The JavaScript code runs in the Popup windows, but not on the website I am browsing
so I am building a function that will change the background color of a website I am browsing, but when I click on the change color button, it only changes the background color of the popup.html, not ...
0
votes
2
answers
97
views
How-to extract Object out of a Function?
Is it possible to extract an Object out of a Function with JavaScript?
The function I received inside of an Object:
function item(){ let product = { name: name, price: price } }
I want to extract the ...
1
vote
1
answer
84
views
What kind of objects are shared between different worlds in Javascript?
The objects I defined in page script seem not accessible in content script for an extension. But the two scripts do share some variables such as window, document, etc. Is there a way to expose some ...