Use this tag for questions related to JavaScript objects.
4
votes
3answers
33 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 proto ...
3
votes
2answers
22 views
Javascript (sub-) Object access by array of keys
Is it possible to set a Variable in an Object by an Array of Keys?
For example i have this Object:
var obj = {'outer': {'inner': 'value'} };
and want to set the Value selected by an Array of Keys:
...
0
votes
1answer
17 views
How to add objects to a key within another dynamically created object in Angular?
I'm using Angular to create a shopping list app. For testing purposes I have two pre-created lists each with pre-created names and items. Eventually the user will initially be presented with an empty ...
-1
votes
0answers
17 views
Arrays within Objects in chrome.storage.local.set [on hold]
How to implement arrays within objects, using chrome storage api to set & get function.
var planets = {
id1:{name: 'jupiter', age: 10},
id2:{name: 'saturn', age:9},
id3:{name: 'mars', ...
0
votes
1answer
42 views
Update values inside javascript object
I am working with the Affirm javascript API and I need to be able to update the values inside the checkout object but am having trouble doing so. I have tried what is mentioned here but it isnt ...
1
vote
3answers
45 views
Can a method of an object store the name of the object itself to be recovered as a string in JavaScript?
if I have:
x=3;
FirstNames = ["John","Paul","George","Ringo"];
LastNames = ["Smith","Jonson","Jones","Doe"];
SemiRandomNumbers= [3,6,7,4,2,1,0,9];
I can set:
ArrayToUse = FirstNames;
...
0
votes
2answers
38 views
Calling a function on click of OK button in a pop up in the Javascript
I have a function in javascript that displays a pop-up. I am doing this in a Sitecore based MVC project and hence I can not do the events in the normal way but following the practice that is followed ...
1
vote
1answer
30 views
Vue js reactivity issue when updating objects inside array used in v-for
I have an application using vue.js. I generate a list of results using v-for in an array of objects.
when I update the object inside nth item in array, using underscore _.extend, the view of project ...
-2
votes
3answers
37 views
javascript object methods prototype
What is the diference in the below aproachs. Which is the best way?
var obj;
obj = function () {
}
obj.prototype = {
getName: function () {
...
0
votes
1answer
25 views
How do I remove dynamically added objects from an array with a button associated with each object?
I'm using Angular to build a shopping list app. I have two pre-created lists, each with two and three pre-created items respectively for testing purposes. Of course eventually there will be no ...
0
votes
0answers
10 views
Copied object generated by Object.Assign() function has side effect?
I have an object named result which is composed of two objects like :
const a = {bar: {baz: 2}};
var b = {foo: 1};
var result = Object.assign({}, a, b);
console.log(result, a, b);
// result -> ...
6
votes
6answers
3k 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) => ...
1
vote
3answers
35 views
js array.IndexOf not working with objects?
I am trying to create an array with objects holding day and time. I am looping over a source where there may be duplicates so I want to check each time that I don't already have the current day and ...
-1
votes
1answer
17 views
Javascript: How to get callback's parameters
I'm trying to somewhat replicate the functionality of forEach so that I can understand it better. In forEach you can pass it in an anonymous function with a parameter 'item' and then it would give you ...
0
votes
2answers
35 views
explanation on javascript function call passing this
I am reading the "Javascript the Good Parts" book and trying out examples to understand the concepts. I came across one example and could not understand. Please look at the code below and let me ...
0
votes
2answers
25 views
javascript MVC structure, map model to rest api
I am trying to make a model (the M in MVC) in my web application, to understand the concept. I am struggling with the async problem that occurs in my code below:
function FruitModel(api) {
...
0
votes
2answers
49 views
How to make the value of one variable of one javascript function available in any other function?
I want the value of someDate to be available to my datepicker's minDate. At present I have kept it as new Date() for it to work, but in place of this I need someDate value. someDate logic is there in ...
0
votes
2answers
31 views
looping through object array returns 'undefined'
I have two arrays.
var fruits = [];
var tasks = [];
When I enter a value in the text field it fires a function that pushes the value to an array. It then fires a separate function that ...
0
votes
2answers
36 views
Generating N urls to make AJAX requests
I'm facing a big problem after creating the API of a backend. I have a form with a GET AJAX method to filter and get results. It works fine but as the urls are generated from the users choice, there ...
7
votes
2answers
182 views
Javascript methods that can not be called from jquery objects?
I was reading Learning jQuery 1.3 (Jonathan Chaffer and Karl Swedberg) and while sorting table, they used .get() before calling .sort(), and said
we need to transform jQuery objects into array of ...
-1
votes
2answers
21 views
javascript Binding function contexts
I saw this code in a javascript ninja's book
<button id="test">Click Me!</button>
<script type="text/javascript">
var button = {
clicked: false,
click: function(){
this.clicked = ...
0
votes
1answer
20 views
complex json into HTML table using javascript
var resData = {"request" : { "empid(Number)":"employeeid(Number)" , "msisdn(Number)":"empmsisdn(Number)" , "num(String)":"number(String)" , "add(String)":"address(String)" } , " response" : ...
0
votes
2answers
16 views
Date list using javascript simple
Hello guys could give me a little help ?
Code here https://jsfiddle.net/pedrowperez/hgb5ufqw/2/`
this is my work.
HTML
<p id="demo1"></p>
<p id="demo2"></p>
<p ...
0
votes
1answer
2k views
Error “Object.keys called on non-object” caused by empty json output
I received an error Object.keys called on non-object. The offending code is;
numberOfEmployees = Object.keys(employee_data).length;
employee_data is a json object that gets assigned json output ...
0
votes
2answers
35 views
A JavaScript function to populate innerHTML based on country language
I typically use JavaScript for UI/interaction purposes, and I'm trying to improve my skills by trying to write more complicated JS.
I have written the following code in an attempt to change the ...
0
votes
3answers
48 views
javascript add function script - can someone explain?
i look for this piece of code in an example that should create functions at object by name.
as i understand it also can create overload of the same function on the object.
function addMethod(object, ...
0
votes
1answer
17 views
Array of Objects not being received as an Array node.js
I am passing a POST that includes an array of "wines". The object on the send looks line. However when I log the request on the server side, the array is a collection of keys and values. What am I ...
-2
votes
1answer
36 views
Why JavaScript return me a wrong result in this subtraction of decimals values? [duplicate]
I am pretty new in JavaScript and I have found a very strange situation doing an extremely simple mathematical operation: a subtraction.
So in a jQuery function I have this code:
saldoRicalcolato = ...
1
vote
1answer
19 views
Singleton objects with prototype in node
I came across below code written in node which I am trying to understand. There is a method process attached to prototype as well as to the object itself. Whats the difference? I understand the ...
-1
votes
1answer
20 views
Getting undefined JSOO
Same code but getting access error on one code block.
//Getting undefined error
//output: Hi Mark, my name is undefined
var john = {
sProp: 'John',
greet: function(person) {
...
1
vote
1answer
63 views
JavaScript Module pattern files concatenation in a one file and using their functions
I write different files under JavaScript Module Patern like this:
file 1.js
var Module = (function (module) {
module.function = function () {
console.log(this.thirdFunction) // This is my ...
0
votes
3answers
29 views
pushing an object onto an array from an array of objects in JavaScript
I'm trying to make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching property and value pairs (second argument). Each property ...
1
vote
1answer
34 views
Add object to array inside parse.com query
I'm having a bit of a strange problem.
I need to add objects to an array, and using the normal array.push(object) doesn't seem to work (nothing is pushed).
The pushes happen both inside and outside ...
0
votes
0answers
18 views
Jquery, Dependent SelectBox Option value not displayed [closed]
I m trying to add values to the select box, which proven to be in vain.
what's the best way?
$("#region_select").change(function() {
var region_id = $(this).find(":selected").val();
var ...
0
votes
3answers
24 views
Use string variable to access value of object
I have a text input.
I want the user to be able to fill out a value in that text input like some of these examples:
results[0].address_components[0].long_name
results[0].formatted_address
...
-1
votes
0answers
16 views
Is there any specific book or website to practice JavaScript? [duplicate]
I am learning JavaScript but along with I need some resources where I can practice the skills I have learnt. If you can suggest me some resources that would great help for me.
Thanks
-2
votes
3answers
26 views
Getting keys of an object that has same values
I have an object like:
Object {v: 1, b: 1, n: 1, m: 1, c: 2, d: 3}
I am trying to collect keys that has same values and generate an array (so in this case [v, b, n, m].
So if I know 1, how can I ...
30
votes
7answers
1k views
Understanding JavaScript in detail: is it a class, a function, or just a variable?
I am a beginner in JavaScript, and I am finding one concept very confusing. Consider the code below:
var person = {
firstName :"Penelope",
lastName :"Barrymore",
// Since the ...
1
vote
1answer
24 views
How do I associate an object with a table row?
I have an array of objects in javascript. Each row in my table represents about 3 properties from one object in the array. I have a jquery event handler for an <input type="text"/>'s blur event. ...
0
votes
3answers
45 views
How to use a variable as constructor property?
function Volkswaggen($options) {
$.each($options, function(k,v) {
this.k = v;
});
}
/* ============================== */
var $polo = new Volkswaggen({model: "Polo", doors: 3});
...
0
votes
2answers
82 views
How can I shuffle or randomize JSON object array data?
I am working on a quiz app. I have been trying to figure out how I can shuffle the options in a quiz question.
I have researched all over, the closest I found was this:
shuffle array in ng-repeat ...
0
votes
1answer
18 views
How to have multiple instances of one jQuery player object in a page (Audio object)
I have made a customised audio player, but the problem is that I can only have one player in each HTML page. Because so since the js code is associated to for example class .playthen if there are 2 ...
0
votes
2answers
33 views
Roles and responsibilties inherited in this browser object's hierarchy
In the below hierarchy of browser objects,
Each object in the above hierarchy would have been created to target certain scope of responsibilities to manage html elements.
In the above hierarchy, ...
0
votes
2answers
32 views
Mapping a list of items in an array to a function parameter
I have an angular controller and service.
The controllers calls the service, and passes some data and an endpoint.
My service performs the http request, however i am trying to refactor my code so ...
573
votes
25answers
436k 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 ...
0
votes
1answer
25 views
Is there a way to use a string inside of a variable to refer to an object property?
Basically I want to use an object to hold certain dates. For example:
var date {
jan26: 'Today this happened'
};
Then get the current date and put it into a string. For example: var today = ...
0
votes
3answers
49 views
Why getElementById returns null when called inside a Class? [duplicate]
I have a class like below and I want to pass an element for further customization. The class should be responsible of setting up the size of the box and adds elements to it. I having hard time ...
0
votes
2answers
38 views
Why I can't perform the toFixed() function after the sum of 2 retrieved values?
Into a JQuery script I have the following problem trying to use the toFix() JavaScript method on a number.
So I have the following situation:
var anticipoProgetto = $("#valoreAnticipo").text();
var ...
0
votes
0answers
10 views
Firefox selectionStart generates an error on some elements
I'm having trouble detecting whether an element has a selection or not in Firefox.
See https://bugzilla.mozilla.org/show_bug.cgi?id=1078702, which has been closed as not a bug.
'selectionStart' in ...
-2
votes
1answer
35 views
can somebody help me understand this more. javascript selection
how do this work? and what are other ways to do it??
//------------------------------------
redirect = function(sectionName){
document.location.assign('about/' + sectionName + '/');
};