Use this tag for questions related to JavaScript objects.

learn more… | top users | synonyms (1)

0
votes
2answers
38 views

Can I get one symbol from string after clicking?

I have DOM document with text content like as: <p>Content scripts aren't completely cut off from their parent extensions. A content script can exchange messages with its parent extension</p&...
26
votes
4answers
15k views

using reserved words as property names, revisited

Can a reserved word be used as an object's property name? This issue was raised in indirectly previous a stackoverflow question. the answer seemed general consensus by @Squeegy: You can use those ...
1
vote
2answers
36 views

Get index of array's object item by property and value

I'm having troubles with updating found object. I also tried Find object by id in an array of JavaScript objects and Get JavaScript object from array of objects by value or property Please help. ...
1
vote
4answers
158 views

What's the difference between a regular push and an Array.prototype.push.apply

I don't quite understand the difference between the following 2 lines of code. In my code, the line with "apply" works the way I want it to, and the line with just regular push doesn't. So what is ...
0
votes
0answers
16 views

Regular expression to escape inner double quotes in json

I have an issue, I was wondering if somebody could help me with a regular expresion to replace this {"name": "Raul "the cat" Gonzalez"} to this {"name": "Raul \"the cat\" Gonzalez"} In order to do ...
0
votes
4answers
47 views

javascript - how to get an object to return a value that is not the object itself

When creating a x = new Date() object, if you put it into console.log(x) a string will be output. Is there a way to make a custom object that will return a different value that is not an object ...
-2
votes
4answers
75 views

How do you put the last character 1st in a string [closed]

The R is displaying last in the string initially it must display first how can I put the last character before the number value in the string so that it can display at the beginning of the value ...
0
votes
2answers
52 views

find sum of Boolean values JavaScript object array

Hi i am trying to find the sum of Boolean values in the object array in JavaScript My json like be var myoBj = [{ "id": 1, "day": 1, "status": true }, { "id": 2, "day": 1, "status": ...
2
votes
5answers
527 views

Why can't I set a JavaScript function's name property?

I am learning JavaScript and read that functions are like objects and can have properties set like this: var person = function(){ } person.name="John Smith"; //output "" person.age=21; //output 21 ...
-2
votes
5answers
29 views

Benefit of using bracket notation (with variables) to access a property of an object

While utilizing alternatives such as the dot operator make sense when needing to access some stored information, I'm having a little bit of difficulty understanding why and in what scenarios we would ...
0
votes
1answer
62 views

ImmutableJS: merge two list of objects, without duplicating them

Supposing I have the below: var allFoods = Immutable.List(); var frenchFood = Immutable.List([ { 'type': 'french fries', 'price': 3 }, { 'type': 'petit gateau', 'price': 40 }, {...
0
votes
1answer
41 views

Javascript object property gets updated on assignment [duplicate]

I have created a JavaScript object like below - var objtvar = {defaultPoints: [[0,0],[0,-10],[2.5, -10], [2.5, -10],[5, -10],[5,0]]} I need to assign the defaultPoints property to another array and ...
0
votes
1answer
35 views

Different JS Namespace declarations

I wonder, are the following code example the same? Version 1: var myNamespace = {}; myNamespace.say = function() {...} Version 2 (JS-Fiddle: https://jsfiddle.net/542wbkat/) : var myNamespace = new ...
0
votes
3answers
40 views

Using variables as keys in Object supplied to Object.assign

I am using Object.assign to get a new copy of an Object with added properties from another map. This is usually as simple as Object.assign(existingObject, {"new_key", "new_value"}), but when "new_key" ...
0
votes
0answers
22 views

Illustrator CS6 tracingoptions maxColors not working?

I am using extendscript to create a script for CS6. I have reffered to the PDF here: http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/illustrator/scripting/cs6/Illustrator-Scripting-...
0
votes
0answers
16 views

Window.closed function works even before closing the window

I am opening a window from a page ( parent), using the openPopup() function. when the child window closes, I need some activity in the parent window. Some of the IE browsers, this is not functioning ...
1
vote
1answer
21 views

Accessing 'this' inside an independent function in a Constructor

I have a Dog Constructor as follows: var Dog = function(name,type) { this.name = name; this.type = type; this.normalObjFunc = function() { this.name = "kl"; } var retfunc = ...
0
votes
3answers
38 views

React component DOM not updating

I have an array of objects. Each object represents a product and they are added and removed from this array and the DOM reflects this properly. Problem is when I update one of the properties of these ...
2
votes
1answer
28 views

JavaScript Prototype Object.create

I have two version code let Animal = function() { } Animal.prototype.voice = "Miau" let Cat = function() { } Cat.prototype = Object.create(Animal.prototype); ...
0
votes
1answer
23 views

Ionic2 private property in a class always empty even if set in that class

I'm new with Ionic2, and TypeScript and try to play with Classes, properties, getters and setters. My first class just initialize some datas in a webSQL database and expose methods that retrieve infos,...
11
votes
8answers
20k views

jQuery create object from form fields

How can I create a object with a form's fields and values? like this one: { fields: { name: 'foo', email: '[email protected]', comment: 'wqeqwtwqtqwtqwet' } } assuming the ...
-3
votes
2answers
38 views

Returning an object from a function in JavaScript

I have a function that returns an object in javascript. The objects returned are instances of a "messagePack" that I want to send to the server. Each messagePack will be different. E.g.: function ...
5
votes
4answers
61 views

Trying to understand scoping within two short JavaScript functions

What is the difference between the following two JavaScript functions? I know variables declared with var are local inside the function, and if declared withthis` keyword are exposed to outer word. is ...
-1
votes
0answers
47 views

I need to write a cycle, that will fill object in object

I have this code that makes array, but I need object in object: var testInfoObj = { "test_id": test_id, "iblock_id": iblock_id } var answerObj = { "question": question, "question_id": ...
0
votes
2answers
31 views

How to access object property in module.exports

I am curious about how to access another object property in module.exports. here is the case : module.exports = { text: 'abcd', index: (req, res)=>{ console.log(text) <-- ...
-7
votes
0answers
19 views

Generate an internal structure (filling) for an object defined in an .off file [closed]

Among many formats used for 3d representations of objects the .OFF (DEC object file) is one of the simplest. a) Consider the problem of generating an internal structure (filling) for an object defined ...
1
vote
1answer
26 views

How to dynamically change the key names of object properties in an array

I have an array of objects, like so: arr = [{"timeslot":"6am7am","AVG(Monday)":10,"AVG(Tuesday)":11,"AVG(Wednesday)":7}] Each object will always contain the "timeslot" property, and can contain any ...
0
votes
1answer
42 views

Iterating through an objects values

Im working with OOP and looking at how to iterate through an objects values, as an example, this code: var numbers = { one: "number one", two: "number two", three: "number three", ...
88
votes
2answers
112k views

How to copy JavaScript object to new variable NOT by reference? [duplicate]

I wrote a quick jsfiddle here, where I pass a small json object to a new variable and modify the data from the original variable (not the new variable), but the new variable's data gets updated as ...
0
votes
1answer
36 views

HTML element attached to JS object

I just stater a bit of OOJS but I can't get my head around one thing, making an object for and HTML element and adding events to it. For practice sake I had an idea to make inputs that can be ...
485
votes
29answers
370k views

Check if a value is an object in JavaScript

How do you check if a value is an Object in Javascript?
-2
votes
2answers
40 views

javascript object of object from json with angular - data not returned correctly [duplicate]

I have code that I fetch data from json file return $http.get(serviceBase + 'Airlines.json').then(function (results) { findAirport([results.data]); // will return later } ...
0
votes
0answers
30 views

Strange calling on object [closed]

When I was roaming the internet and learning JS, i found this code and I am a bit confused. function escapeChars (testString) { var map = { '&': '&amp;', '<': '&lt;', ...
0
votes
2answers
32 views

Is it safe in Javascript to assume the existence of “constructor” property on variables with values other than “null” or “undefined”?

I was wondering if it is safe to assume that in JavaScript a variable will always have a "constructor" property if its value is not "null" or "undefined". I ran into a situation where I had to check ...
2
votes
2answers
34 views

How to iterate an array of objects and group the property values by their key name?

I have an array of objects named data, like so: data = [{"timeslot":"7pm-8pm","Monday":60,"Tuesday":55}, {"timeslot":"8pm-9pm","Monday":70,"Tuesday":60}, {"timeslot":"9pm-10pm","...
0
votes
1answer
20 views

How to reference an array dynamically using the name of an object's property

I want to iterate an object's properties, and push the value of each property to an array sharing the property's name. How can I reference the array name dynamically using the name of a property? ...
0
votes
2answers
12 views

Cannot read property 'decomposeTextShadow' of undefined [duplicate]

I have the following object: var decomposer = { decomposeColor: function(color) { }, removeColor: function(code) { }, decomposeTextShadow: function(code) { ...
2
votes
5answers
39 views

How do I apply methods from a constructor object to an arbitrary object [duplicate]

I have a constructor object that has various fields; For a simple example, say function Person(id, name) { this.id = id; this.name = name; etc. this.someFunction = function(xxx) {...} } Now, ...
0
votes
1answer
42 views

how can i check whether which kind of function is they are and how can clear the clearIntervals if exists

1) How can i check which kind of javascript function is ? In this below code.i have assign idlecheck to the setInterval function, normally we have check the function in javascript as below. if (...
-5
votes
0answers
44 views

Want to write code to fetch data from nested javaScript object

var obj = [{ name: "Vi jay", age: 20, marks : {s1:50,s2:60,s3:30,s4:70,s5:80,s6:45,s7:34}; }, { name: "ram", age: 20, marks : {s1:50,s2:60,s3:45,s4:70,s5:20,s6:45,s7:34}; },...
0
votes
1answer
37 views

How to pass a variable in replace function

I have been using the replace function since long to remove the classes from JavaScript, Now I was making the JavaScript function for that through which, I can pass an element and the class name to ...
0
votes
2answers
33 views

Getting the sum of the values of the properties of an object

I'm looking to take the result of a survey that I created using JSON, add up the values associated with the objects from that survey in order to produce a sum. However, I am unsure of how to call upon ...
0
votes
2answers
53 views

Why clearInterval not clearing the setInterval timer

i have creating an simple Timer service.In the timer service, i am monitoring the user for each minute. while page load,have set 3 minutes to get an alert to logout and before 1 minute which means 2 ...
-5
votes
0answers
33 views

How can I upload file with desire with path use value in type=“file” ???

I want to uploud file with on desire path using post method in form is that possible.. <form action="example.php" method="post" enctype="multipart/form-data"> I have a <input type="file" id=...
1
vote
4answers
1k views

Using JavaScript what's the quickest way to recursively remove properties and values from an object?

I need to find the fastest way to remove all $meta properties and their values from an object, for example: { "part_one": { "name": "My Name", "something": "123", "$meta": { "test"...
0
votes
0answers
21 views

Console says typeof variable is object, but is somehow undefined [duplicate]

I'm trying to take an object and extract some contents into a new variable, but I'm running into undefined variable issues. Below is my code: <script src="https://apis.google.com/js/api.js"><...
5
votes
4answers
6k views

Navigating to previous and next item in a Javascript object

I want to navigate up and down an JavaScript Object given an item of an object. An example object: var items = { "5" : ["name", "link2"], "8" : ["name 2", "link 2"], "11" : ["name 3", "link ...
1
vote
1answer
50 views

Extraction of string using regex in javascript

I have a string of the following format: "hello(%npm%)hi" My goal is to split the string into three parts a) hello b) (%npm%) c) hi I am using regex as follows: var myString = "hello(%npm%)hi"....
0
votes
2answers
45 views

Retrieve nested objects JavaScript

My object from Firebase when I console.log: Object {AW: Object, Qdoba: Object} Then under the restaurant titles of AW and Qdoba, I have title and address which I can expand on and see in my console. ...
0
votes
1answer
44 views

Can't iterate over my array/object. Javascript, React Native

I really don't understand what could be going on here. So I have a function which takes a 2d array and a string and iterates through the 2d array and checks if any subarrays contain the string. But ...