Use this tag for questions related to JavaScript objects.
0
votes
1answer
16 views
How can I access a nested class object in Javascript?
I'm using the node scheduler & it creates an object like so:
{
recurs: true,
year: null,
month: null,
date: null,
dayOfWeek: null,
hour: null,
minute: Range { start: 0, end: 59, ...
0
votes
2answers
33 views
How to combine two array objects if a key value matches in both arrays
I am trying to combine two array objects with different array objects based on flight key.
If the value is matched in a2, I want to merge it with a1 and create new array.
All data in a1 must be there ...
-1
votes
0answers
30 views
Break up large json file into a series of smaller objects
I have a json file that has 7500 objects and I need to break them down into JSON objects of 100 in size. How can I go about doing this?
Details:
I am using JavaScript
Yes we will use a loop
I ...
0
votes
2answers
29 views
Adding complex objects to an array using foreach or map with javascript
I've reviewed similar questions here on stackoverflow, read the javascript MDN, and not found comparable examples, and am asking now for advice on how to create the desired array from the given array. ...
0
votes
1answer
36 views
How to merge two objects with different structure in javascript
I Have two objects with different structure, trying to merge this two objects with matched data based on a key value, and make a new object with complete data from object1 and object2.
my Object1
{ ...
1255
votes
27answers
811k views
Length of a JavaScript object (or associative array)
If I have a JavaScript object/associative-array, say
var myArray = new Object();
myArray["firstname"] = "Gareth";
myArray["lastname"] = "Simpson";
myArray["age"] = 21;
is there a built-in or ...
2
votes
4answers
39 views
What event can I use to a detect a value change in an object AND get the key of the changed value?
I have a Object that contains some (simple) key: value pairs like this:
var things = {
"0": "apple",
"1": "mango",
"2": "pear"
// ect...
};
Is there a built in function or method in Object....
0
votes
1answer
32 views
What does the term `functions objects` in Javascript actually mean?
After reading a lot, I still don't quite understand the term function objects in JS. From what I have read, following are my interpretations. Please correct if I'm wrong.
function myfunc(x){
return ...
31
votes
9answers
24k views
Flatten a javascript object to pass as querystring
I have a javascript object that I need to flatten into a string so that I can pass as querystring, how would I do that? i.e:
{ cost: 12345, insertBy: 'testUser' } would become cost=12345&insertBy=...
0
votes
1answer
39 views
How to numerically sort nested keys in local storage
The Problem
I've been trying to figure out how to sort my local storage object by its keys which are milliseconds.
Example Code
// function that saves to local storage
function ...
0
votes
3answers
29 views
Iterate through Object keys in Javascript
Having an object like this:
req.body = {
currency : "USD",
item_name_1: "something",
item_price_1: "something else",
item_name_2: "something",
item_price_2: "something else",
...
1
vote
3answers
33 views
javascript: create an array of JSON objects from linking two arrays
let's say I have two arrays:
var meals: ["breakfast", "lunch", "dinner"];
var ingredients: [["eggs", "yogurt", "toast"],["falafel", "mushrooms", "fries"], ["pasta", "cheese"];
Is there an ...
1
vote
2answers
30 views
How to apply an expression towards only numbers and not strings
This should be an easy one but I'm having a brain fart today.
so..
var cat = {
name: 'catcat',
age: 6,
color:'brown'
}
I want to return an object where only numbers get squared. So far I have..
...
-1
votes
1answer
22 views
How to destroy variable when change URL(any browser) in JavaScript or Jquery
Today use this Code but this code some time not properly work
**Problem : Page refresh then call unload() but some time user change URL directly at that time not call unload() because website change....
0
votes
1answer
39 views
Ewa Namespace Javascript API Embedded Excel Web Part / Web App Dashboard - setParametersAsync method creates infinite loop
The setParametersAsync method takes a JavaScript object as it's first parameter. When I pass a literal object with a single value assigned to a key, the method calls it's callback function, executing ...
0
votes
0answers
11 views
How to get data “out of” d3.xml(…)? [duplicate]
I use Array.push() inside a d3.xml function to gather some data from a xml.
But it doesn't seem to work, my Array.length = 0 whereas the console.log SHOWS ME that my data are here...
You can see it ...
3
votes
3answers
32 views
Convert object with one property into parent property
I have converted javascript object from xml, this is example of object:
{
name: 'current name',
attr1: 'attribute1',
attr2: 'attribute2',
address: {
name: 'name1',
value: {
...
0
votes
2answers
30 views
Splitting a Bill - JavaScript exercise
I'm currently learning JS, and I'm trying to work through a coding exercise. So far, I've managed to piece together the following code using plenty of resources on parts of the code offline and online....
-3
votes
1answer
26 views
javascript objects how to duplicate functionality
when I run this code
d = new Date();
alert(d);
I get this output:
Fri Sep 30 2016 22:09:45 GMT-0400 (Eastern Daylight Time)
how can I duplicate this with my own objects? instead of having to do ...
2
votes
3answers
30 views
Iterate and Enumerate Key Value Pairs of Multiple Arrays in an Object
My question is in regards to the following function:
function loadConfigurations(configs){
console.log(configs);
}
The 'configs' object that the loadConfigurations function receives, contains ...
0
votes
2answers
28 views
How to filter options of a <select> by textfield with pure javascript onkeyup?
I have a select with some values. When the user enters a vehicle in the search box, the drop down gets filtered to the option value that matches in the search box. I am able to get this first part of ...
0
votes
3answers
40 views
Is it possible to populate an Object instance by looping through an array?
I'm making a journal app and need to create an object instance every time inputs are submitted on my html form.
I want to create a loop that takes the inputs in results and converts them to values ...
-1
votes
2answers
28 views
Using Array.from() in JS
I am a little confused with Array.from() in JavaScript. I know/think that is turns array-like values into arrays, but why, if Array is an object, do we not have to use the 'new' keyword to instantiate ...
20
votes
3answers
27k views
Angularjs merge two objects
For instance, from these two objects :
var object1 = {
"color": "yellow",
"size" : null,
"age" : 7,
"weight" : null
}
var object2 = {
"color": "blue",
"size" : 51,
"age" :...
0
votes
0answers
26 views
How to remove a JavaScript component (object) [duplicate]
So I have a very basic game and I need a "Restart" button to work instead of refreshing the game to restart the game. When I click the button I want to remove everything and then load the main ...
1
vote
1answer
105 views
D3.JS bar graph column offset while adding new data
I'm currently working with D3.JS attempting to add to an existing graph every 24 hours. Using JSON data like this:
[{"name": "bill", "val": 28}, {"name": "kevin", "val": 46}, {"name": "ryan", "val": ...
0
votes
2answers
16 views
Running an animation when a particular child element is clicked, but doing nothing on all other children
I am attempting to get the following code snippet to work the way I want it to. I only want the sub-menu to slide back to the right when the "li" element with the class "back" is selected. Right now, ...
0
votes
0answers
7 views
TableSelectDialog OData binding not executed during instantiation SAPUI5
When a TableSelectDialog is instantiated, the OData binding is not executed. It gets executed during the subsequent times. What is wrong with my implementation. Please find the MWE:
eventName: ...
-1
votes
3answers
29 views
How to safely wrap an object into an array in JavaScript
I have a function that takes in an Array, iterates over it finding all Objects and displays them to the UI.
In rare cases, I have to supply an Object (result from a WS as application/JSON) which is ...
30
votes
5answers
13k views
How to set up JavaScript namespace and classes properly?
It seems there are so many ways to set up a JavaScript application so it is confusing as to which one is correct or best. Are there any difference to the below techniques or a better way of doing this?...
0
votes
3answers
32 views
Merging values from multiple objects inside array
I have 3 separate arrays with 3 objects inside each of them:
[{Index: 1}, {Index: 2}, {Index: 3}]
[{Placement: 'Wall'}, {Placement: 'Roof'}, {Placement: 'Door'}]
[{Color: 'GREEN'}, {Color: 'WHITE'}, {...
1
vote
2answers
29 views
Difference between two JavaScript classes and why prototype does't work on Emp class
(function() {
var Emp = function(_name, _salary) {
var name = _name;
var salary = _salary
return {
name: name,
salary: salary
};
}
Emp.prototype.work = ...
1
vote
0answers
31 views
jQuery variable in array path [duplicate]
I am passing a variable into a function (an array in this case). How do I use a variable in that array to select data from another array which has a key with the same name? I have tried various ...
4
votes
2answers
42 views
What happens when you instantiate a new Object(1) with a parameter in JavaScript?
What happens when you call:
new Object(1)
When I tried it out, it returned:
[Number: 1]
I want to understand what is going on there. Any info would be appreciated.
0
votes
2answers
19 views
Javascript object/function accesibility inside another one
I was looking for best solution, but I dont really what keyword should I look for. I need a bit of explanation of my problem :) Thats my code:
function fluidEdge(params) {
var fluid = {};
fluid....
-3
votes
0answers
35 views
How to count the occurrences in a object (not array) [duplicate]
Not sure how to get started on this. The data is user input with unknown values and unknown number of occurrences. Will be a string using letters, numbers and punctuations.
The Object will be data[i][...
0
votes
1answer
14 views
Keep the context of this after a click event in a function object
I've got an object with functions. Here's a simplified version:
var app = {
functOne: function(){
document.querySelector('button').addEventListener('click', this.functTwo);
},
functTwo: ...
1
vote
2answers
48 views
Correct way to override this JavaScript class method
Apologies if this is quite an obvious, well documented one but I've not found much documentation which helps me with how I should best go about overriding a JavaScript class method when it has been ...
735
votes
27answers
602k views
Find object by id in an array of JavaScript objects
I've got an array:
myArray = [{'id':'73','foo':'bar'},{'id':'45','foo':'bar'}, etc.]
I'm unable to change the structure of the array. I'm being passed an id of 45, and I want to get 'bar' for that ...
1
vote
3answers
21 views
JavaScript - change only SPECIFIC object field value at runtime
I have this JS code:
<script type="text/javascript">
var triangle = new Object();
triangle.sideA = 3;
triangle.sideB = 4;
triangle.sideC = 5;
triangle. getArea = function () {
// ...
1
vote
1answer
8 views
Why the if statement is not accepting bracket-notation instead of dot-notation?
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "...
1
vote
3answers
27 views
How to put data into multi dimensional array in js inside the loop
How can we put data into multi dimensional array or json within a loop.
I know that it's possible to store multi dimensional data at one time, but I want it inside the loop as I have described in the ...
-1
votes
1answer
14 views
JavaScript bind arguments correctly [duplicate]
I've got the following bootstrap3 button code which is enclosed inside a container div. The button has no text apart from a plus icon.
<div id="container">
...
<a type="button" ...
6
votes
3answers
74 views
Why does new Number(2) != new String(“2”) in JavaScript
The following evaluate to true:
new Number(2) == 2
new String("2") == "2"
Obviously, but so do the following:
"2" == 2
new Number(2) == "2"
new String("2") == 2
So can someone explain clearly ...
0
votes
5answers
44 views
adding properties to an existing object inside an array
I am picking an array with few object on it from an external file.
Using:
app.controller('mycontroller', function($scope, $http) {
$http.get("file")
.then(function(response) {
$scope.lols = ...
415
votes
27answers
321k views
0
votes
2answers
32 views
Find and retrive object value by key, include nested objects
I am trying to find a value by key without knowing the object, include nested object, so the function will get a key and a object and return the value or undefined.
This is my function:
/* Iterate ...
-2
votes
2answers
45 views
Transfer value of object inside array to another array
I have an object like this:
var animals_data = {
category : [
{
class : "Reptiles",
animals : [
{
image1 : "some image",
image2 : "some ...
0
votes
2answers
44 views
Convert object to array of type integer and sum the values
I want to convert JavaScript object to array of type integer and add all the values in array and convert back to object.
So far I tried the following:
//Convert object to array
var arr = Object....
1
vote
2answers
26 views
how javascript add property to an object?
I was reading javascript questions where i found this piece of code
var a={},
b={key:'b'},
c={key:'c'};
a[b] = 123;
a[c] = 456;
console.log(a[b]); // o/p - 456
can anybody make me ...