Use this tag for questions related to JavaScript objects.

learn more… | top users | synonyms (1)

1
vote
2answers
21 views

Can't clear inputs in javascript

I'm doing practical javascript course on watchandcode.com and my code is exactly the same as the instructor's, but the part where it clears the inputs does not work here. changeTodo: function () { ...
0
votes
0answers
14 views

How are native objects implemented in browser in JavaScript? [duplicate]

Whenever we declare var item = "string"; It means we are creating a string variable but surely a string object is made in background so that we can access item.length; It means item has ...
0
votes
1answer
15 views

Clear search bar tool on google map after having searched for a place

I built a search bar for my map in jQuery which is integrated with the javascript object inside my map in order to display each place I indicated in my map as a marker. The problem is that, when I've ...
186
votes
3answers
102k views

How to return value from an asynchronous callback function? [duplicate]

This question is asked many times in SO. But still I can't get stuff. I want to get some value from callback. Look at the script below for clarification. function foo(address){ // google map ...
83
votes
2answers
173k views

Encoding Javascript Object to Json string

I want to encode a Javascript object into a JSON string and I am having considerable difficulties. The Object looks something like this new_tweets[k]['tweet_id'] = 98745521; new_tweets[k]['user_id'] ...
-8
votes
1answer
41 views

Combining two arrays into one javascript json object

I have two arrays: var itemname = [ "t-shirt", "trouser", "vest" ]; var itemqty = [ "3", "5", "2" ]; I want to combine them into: var keyval = [{ itemname: "trouser", itemqty: 5 }, { ...
0
votes
0answers
24 views

Not getting the updated value of global variable in another function [duplicate]

I have declared two functions and one global variable . i am setting the global variable value in first method and trying to access the value in second method . var Result=[]; setResult(); ...
0
votes
0answers
28 views

How to use async in ES6 constructors to call internal methods?

I am using async in a constructor to sequentially call internal methods. But, due to problems with localizing this, I have to wrap these functions in an anonymous function. I have to adopt a similar ...
-1
votes
0answers
7 views

how to display multiple rocords of array elements using JavaScript

I want to get four data's such as name address age and phone number from multiple user. And I have to store it in array and to display as table structure. Please help me how to write a HTML and ...
0
votes
5answers
59 views

How to simplify / streamline this code? (Object check into function call)

First this is what my urlObject looks like: { term_id_1: "2155" term_id_2: "2894" ticker_1: "SPY" ticker_2: "SPY" } I can have up to 3 terms and tickers so like: ticker_1, ticker_2,...
0
votes
0answers
37 views

TypeError - .replace is not a function

Im getting a "is not a function" error, and i have no why is happening, the issue is how i resolve in this case. I have a data that is received from the user has string, and after i receive the data ...
0
votes
1answer
45 views

Javascript removing an object from a function

I am creating a game in which I have an array of objects, one of the arrays holds all the missile objects. This array is needing to have missiles removed from it frequently as they hit walls (or ...
-1
votes
2answers
42 views

JavaScript Object definition return an String instead the entire object

I wonder if we can define an Object like it is location object... example: var a = {a:'asd', b:someFunction}; console.log( a ); //Desired: 'asd' //Actual: Object {a,b}... console.log( a.a ); //> '...
-7
votes
1answer
39 views

Javascript or JQuery not understanding [on hold]

I am very new to the front end programming and I sometimes do not get the meaning of the shortcuts of the javascript and jquery. I have some code template to work on and I do not understand clearly ...
0
votes
2answers
43 views

Javascript three dimensional arrays vs Object literal

Which of the following two scenarios performs better and feels more natural to the langauge: Using Object literal: var object = { 'key1': [e1, e2, e3, e4, .., en], 'key2': [e1, e2, e3, e4,...
5
votes
2answers
68 views

Why isn't it possible to delete Javascript variables automatically generated from the DOM?

It may not be common knowledge, but "Javascript on many (all?) modern browsers seems to create variables on the window object for DOM elements with IDs". Knowing this I'd like to be able to delete ...
0
votes
1answer
41 views

Duplicate sub arrays

I have an array (generated dynamically) which contains objects. Those objects contains arrays which sometimes are duplicated. I wonder how could I make a function to check the arrays contained in ...
0
votes
2answers
43 views

How to initialize an associative array from an object?

Given this.themes = [ { name: 'Material Teal', colors: { 'primary': { default: [ 0, 150, 136], a100: [167, 255, 237], a200: [100, 255, 218], a400: [ 29, 233, 182], a700:...
0
votes
0answers
7 views

Creating Custom Client Script access properties and moving inlined code to external js file

In an asp.net project I have a usercontrol and have added the below code to associate a class with the control. Type.registerNamespace("SC.Controls"); // Constructor SC.Controls.LocationMap = ...
2
votes
2answers
39 views

How to bind an arguments object to a function in JavaScript?

Is there a way to bind an array/arguments object to a function, similar to how .apply allows for calling a function with an array of arguments? For instance, I am building parts of the underscore ...
2
votes
1answer
31 views

Count No.of unique attribute occurances with respect to another attribute in Array of objects

In the below data set, I want to count number of aKey with respect to each bKey. Such that for every bKey how many unique aKey are there. Like if a certain aKey is occurred already then for that bKey ...
1
vote
0answers
16 views

Overlong Object Manipulation for Order Form

I'm trying to write an order form for a food delivery website (to learn more about objects in Javascript), so that each item, when selected, populates an array. It should also recognise the quantity ...
0
votes
0answers
23 views

Adding event listeners and passing in the object [duplicate]

This is my current code: Index.html AddEventListener('click', 'a[data-requestpartial]', function (obj, e) { e.preventDefault(); // Error is happening here. this is undefined....
0
votes
1answer
53 views

Javascript: Am i doing this as efficiently as possible?

This is my first post, im new to coding, and this is my first little project using objects. I need some expert eyes to tell me if im doing this the long way, or if this is actually the fastest way to ...
0
votes
3answers
41 views

What is the relationship between JavaScript Objects and HTML

I have been web coding for over 4 years now and for some reason this question popped into my head. I can write HTML, CSS, and JavaScript and I understand the DOM, but I realized if the DOM is merely ...
3
votes
5answers
70 views

How to transpose a javascript object into a key/value array

Given a JavaScript object, how can I convert it into an array of objects (each with key, value)? Example: var data = { firstName: 'John', lastName: 'Doe', email: '[email protected]' } resulting ...
1
vote
3answers
66 views

compare 2 arrays to see if objects exist

Array 1 = [object] Array 2 = [object, object] Let's say in array 1 object is : { 'name': 'apple', 'id': '' } and in array 2: object1: { 'name': 'bananna', 'id': 2 } object ...
1
vote
0answers
29 views

When I run setState with a large object my component gets removed from the DOM

I'm building an app that lets you organize emojis via drag and drop. I have a method that runs on drop that sorts a large array of emoji objects. When I run setState and commit the object back into a ...
-1
votes
0answers
16 views

compare ajax request.responsetext with some string!! i know this topic is already there, but it haven't sort this issue out

i understood above program but it didn't work for me. var request=new XMLHttpRequest(); function check_username(){ var name123 = document.form1.ui.value; var url = "...
0
votes
2answers
27 views

How do i change an image into a different image by clicking on it with onclick?

How do i change an image into a different image by clicking on it with onclick? #box{ height:200px; width:200px; background-color:gold; } <body> <div id="box"></div> <...
1
vote
1answer
23 views

How do I connect two objects with a method to return a new object

I have 2 class objects A and B. Both contain an attribute called 'prob' (for probabillity). Now I want to write a Method, which connects both objects and creates a new one, with a defined attribute '...
2
votes
2answers
47 views

Why adding a method on function directly did not work like function.prototype?

I am learning and trying to understand JavaScript Objects deeply. I learnt Object prototype via example below. var MyObj = function(){ this.Name = "Stackoverflow"; } MyObj.prototype.prop = "OK"; ...
0
votes
1answer
47 views

finding a value in an object

I have an object: { id: 16, defs: { name: "Depot (Float)", field: "Depot" } } And an array (which can have more than one object in it but for the purposes of this only has one): [ ...
-2
votes
1answer
48 views

Array.splice (+ loops) vs Delete Object[…] vs Object[…] = undefined

So I have a bunch of (10000+) objects that I need to remove/replace for simplicity, we can presume that the object contains a (String) Unique 'id'. The items often need to be renamed (change id), but ...
-1
votes
0answers
12 views

Javascript Multiple Slider plugin breaks when multiple markdowns on same page

A basic slider, works wonderful when the markdown it's only used once per page, but if it happens that there's two markdown slider's (<div id="slider"></div>) per page. it will break. $(...
0
votes
0answers
23 views

Clarification on Prototype and Object.create pattern

<html> <head> <meta charset="UTF-8"> <title>Animal</title> <script type="text/javascript" > var Animal = function () {...
1
vote
1answer
23 views

Access properties of javascript object from a function which is passed into it's constructor

The below code doesn't work because at the time the function is called this=window. I was expecting this = controller.actions.project but have since learned more about how this keyword works and now ...
2
votes
2answers
37 views

What's the difference between return vs. new keyword Constructor patterns?

Consider the following piece of code: var Animal = function(name) { return { name: name, speak: function() { return "My name is " + name; } }; }; var cat = Animal("Kitty"); My question ...
0
votes
4answers
48 views

Push an object at a key in an object array javascript

I have an array that stores various objects. Looks like following: [ 'key2': { id: 'WA3WA9WA2WA4WAdWA1WA2WAb-WAeWAdWAaWAf-4WA1WAaWA6-WA8WA8WAeWAc-WAfWAdWAbWAeWAaWA5WA1WAfWAbWAdWAfWA2', d: undefined, ...
0
votes
2answers
33 views

How to add object in array Angularjs and show this?

How to add object in array and show it on web-page? http://plnkr.co/edit/19w1Q3XhoWQcpxm5SuxX?p=preview $scope.add = function() { $scope.items.push($scope.item); $scope.item = ''; }; When I try ...
3
votes
1answer
29 views

JS add property to object via function call from construcator

I can't figure out why the following code: function Foo() { this.a = "a"; this.c = add(); } var add = function() { this.b = "added"; } obj2 = new Foo(); ...
10
votes
8answers
4k views

Mongoose/MongoDB result fields appear undefined in Javascript

Is there something that I'm missing that would allow item to log as an object with a parameter, but when I try to access that parameter, it's undefined? What I've tried so far: console.log(item) => ...
0
votes
4answers
54 views

Retrieve property from JavaScript object

Update: This code just works :) Other logic in my page caused a problem I'm reading out a JavaScript object from a jQuery data object: $('body').data('myvals', {var1:"lorem",var2:"ipsum",var3:"...
13
votes
5answers
12k views

Efficiently rename/re-map javascript/json object keys within structured array

I have some structured JSON data like so. Let's assume this is interchangeable, via JSON.parse(): [ { "title": "pineapple", "uid": "ab982d34c98f" }, { "title": "...
0
votes
3answers
23 views

Instantiating a New Object References The Same Property

Why when I instantiate a new object in JavaScript that has another object as one of its properties, does it always reference the same object? For example function test() {} test.prototype.state = { ...
0
votes
1answer
24 views

JavaScript: Nullifying a variable that points to an object nullifies the variable not the object?

Essentially, I have a heavily nested object, so I create variables to access that object so i don't have to write the entire nested object in order to perform an operation. The problem is that when I ...
1
vote
3answers
38 views

valid object property in javascript

how can i check if any javaScript object's property exists and if it exists then it has a valid value? actually,i am a beginner and trying to solve this- Check if the second argument is truthy on ...
0
votes
3answers
49 views

How to add objects into an array without repeating value of one of the properties of objects in JavaScript?

I am trying to insert data into an array. The data is of object form with 2 properties name and value. I am retrieving the data from a different array object with a completely different structure. ...
-1
votes
4answers
145 views

Can't access variable in Javascript object

I don't understand why I can't access through the b or c variables in the global function of the object object, got some trouble with variables inheritance in JS objects. var object = { a: 'a', ...
1
vote
3answers
70 views

How to use two arrays to form an object in javascript?

I have two object arrays as: array1 = [Object, Object, Object] array2 = [Object, Object, Object] where each Object in array1 is: {property1 : "somevalue"} and in array2: {property1 : Object, ...