Questions tagged [javascript-objects]

Use this tag for questions related to JavaScript objects.

javascript-objects
Filter by
Sorted by
Tagged with
0 votes
1 answer
154 views

In which way can i pass through a method call in JavaScript class

Assume we have some classes A and B: Class A { constructor(a) { this.a = a; }; showInfo() { console.log(this.a) }; }; Class B { constructor(b) { this.b = b; ...
0 votes
1 answer
72 views

the logic here doesn't make sense in javascript

cellColor = {}; cellColor['cel32'] = 'blue'; cellColor['cel24'] = 'blue'; cellColor['cel16'] = 'blue'; cellColor['cel8'] = 'blue'; console.log( (((cellColor['cel32'] === cellColor['cel24']) === ...
0 votes
0 answers
15 views

Check if property exists in object JSChallenger [duplicate]

I am beginner in javascript coding and I struggle to understand why this code is not ok on jschallenger even though VS Code returns the same output as they suggest there.... ***Exercise:*** Write a ...
0 votes
2 answers
3k views

VueJS: Why v-model does not work with a vuejs filter

Why v-model does not work with a filter getUppercase in <input v-model="filterText | getUppercase"> HTML <template> <div class="wrapper"> Check if fruit exist: <input v-...
0 votes
2 answers
221 views

VueJs Reactivity

I have a vueJs component which looks like the following: export default { name: 'componentname', data () { return { items: [] } }, mounted() { this.getItems(); }, ...
0 votes
1 answer
312 views

How to retrieve value of key from an object inside an array

I'm trying to retrieve the merchant name from within the following array: [ { "model": "inventory.merchant", "pk": 1, "fields": { "merchant_name": "Gadgets R Us", "joined": ...
0 votes
1 answer
2k views

Vue.js: Add Promise result to Array

I have the following Vue.js component: <template> <div> <pre>{{ $data }}</pre> </div> </template> <script> import { getPrice, getPriceForTimestamp ...
0 votes
1 answer
4k views

Making Dynamically Set Object Values Reactive in VueJS data() & v-bind: sync Forms

So, I am building a dynamic form generator that generates forms based on an object created in data() as form: {}, then set with question key/value pairs in beforeMount() that are bound to a form ...
-1 votes
2 answers
45 views

Checking for same values and update array

I am working with Nodejs and I am stuck on this given below problem and looking for best practices to do it. I have an array set that would be like this: [ { id: 'something1', score: 180, rank: 1, ...
0 votes
3 answers
858 views

Loop through array of objects, to extract data within nested arrays

Example data set const data = [ { location: "1A", uId: 1, notNeededData: null, components: [ { modelId: "7654", ...
0 votes
1 answer
2k views

Changing complex computed object in vue.js

I have complicated object for a table. Looks like this: { 1510002000: { date: "07.11.17" hours: { 1510002000:{ activity:{ activity: ...
1 vote
1 answer
412 views

How to create a Javascript class that can be instatiated like a C# class/object and consumed in Vue component

I want to create a Javascript class that I can instantiate from a Vue component and call functions on it like in C#. public class MyClass() { public MyClass(string someParameter){ .......
-1 votes
1 answer
94 views

proper way to display and filter an object in VueJS

Right now I have data being returned from an API that is structured like the following {_ids: "690506", _addresses: "987394", _bids: "709395", _sids: "384130"} <ul> {{Intl.NumberFormat("en-...
1 vote
1 answer
449 views

Error: Objects are not valid as a React child (found: object with keys {links}). If you meant to render a collection of children, use an array instead

Im trying to figure out how to handle different API responses and map over them. So i can present them in my application. Handeling the getArrayofObjects function is no problem at all. However, the ...
0 votes
0 answers
22 views

How to avoid "about:blank" while doing form action with javascript? [duplicate]

I am trying to use multiple submit forms in javascript but it opens about:blank along with the requested form actions URLs in next tab my code: <form class="search_content" action="/&...
2 votes
2 answers
68 views

why is the following code not returning sum of all the array elements?

Below is the code, I want to return the sum of all the array elements, why is it not working. I know we don't need the Promise to achieve that but I would like to know how it can be done with a ...
0 votes
1 answer
206 views

Flattening JSON API response in Node

JSON Object returned from API Response: {3 items "total_reviews":574 "stars_stat":{5 items "1":"2%" "2":"1%" "3&...
1 vote
2 answers
5k views

React.Js and Typescript how to read data from JSON?

everyone. I am using MongoDB with mongoose and React.Js. I have a page where the user can display a post. I am sending fetch request to the backend where I am getting this json data as response. { ...
1 vote
1 answer
222 views

Javascript object generator

Is there a generator approach to constructing a mapping (object)? I just need key/value mapping. For generating array, I can write something like this function* rangeA(start, stop) { while(start <...
0 votes
1 answer
31 views

Javascript function settings/options styling questions

I'm sure there are more elegant and shorter ways to write a similar piece of code. What I'm trying to do here is passing slightly different parameters to even and odd elements inside a forEach loop. ...
0 votes
0 answers
77 views

Filter common dates between two arrays in Javascript

So i have this project i am working on where i have an array of Javascript objects, and each object contains different entrys: var array_of_objects = [{ "timeline": [-765, ..., -18342], ...
0 votes
0 answers
17 views

Problem with object handling in Javascript forEach function [duplicate]

I'm trying to do an object manipulation in javascript, but it's not working as expected. The code is this: let data = [{ "Code": "COD01", "Size Options": "85-...
0 votes
2 answers
54 views

Am I just misusing objects in this random lotto generator code?

I've gotten a Random Lotto Generator script to work in JavaScript in one game. Now, I'm trying to get it to function for multiple Lotto games and figured Objects were the best way to adjust to the ...
1 vote
2 answers
569 views

How to download the model as a JSON file?

My model is held in a JavaScript object on the client side, where the user can edit its properties via the UI controls. I want to offer the user an option to download a JSON file representing the ...
29 votes
1 answer
18k views

Object.hasOwn() vs Object.prototype.hasOwnProperty()

The new method Object.hasOwn() returns a boolean indicating whether the specified object has the indicated property as its own property but so does Object.prototype.hasOwnProperty(), what is the ...
0 votes
2 answers
578 views

How to add an object to an array based on its values?

I have an array of objects, it looks like this: [{ Rank: 1, Speed1: 91, Speed2: 457, Username: 'monizotic', ProfileLink: 'profile_link', VerifiedSpeed: null, Video: null }, ...
0 votes
1 answer
460 views

How do I create a quiz app with three different answer modes?

I am trying to create a quiz app which should feature 5 questions, chosen randomly from a bank of questions. But, the there should be three different ways of answering the questions : At least one ...
1 vote
2 answers
426 views

How do I get the value of an Array without knowing the name of the Array

im currently working on a user authentication system using expressJS. Therefore to encrypt my data I am using bcrypt. Then I save the encrypted data to a MySQL Database. Then when logging in I get the ...
0 votes
1 answer
79 views

JavaScript - Ordering an array of objects with a chunk size / repeating pattern

I have some JSON (returned from a DB query, sample below) that I'm trying to figure out how I can order in a very specific manner: +────────────────+─────────────────+─────────────────+ | Desired ...
0 votes
1 answer
238 views

In ReactJS is there a way to iterate through 2 arrays and combine the 2 arrays to be grouped by the data in it?

The title might be a little confusing, but basically I'm working on a project and it requires me to have 2 array of object lists. I have a group array and a values array, I've been looking for hours ...
-2 votes
1 answer
49 views

Find Efficient way of Filtering of two arrays (ArrayA & ArrayB) to make a third ArrayC

Can anyone help me come up with a faster way of filtering the following ArrayC (see below what it should be equal to. ArrayA is self explanatory. ArrayB has inside of each element an object 'data' ...
0 votes
2 answers
294 views

how to fix the number of days o february days selection with my code below

im am making a birthday registration form Help me im trying to fix the date selection of february in every quarter year / year that has equivalent to zero like 2020 when year 2020 % 4 == 0 the number ...
0 votes
2 answers
55 views

Is pushing an object to an array async operation?

I was doing one problem-solving program where I had to find all the pairs from an array that adds up to a target (classic two-sum program just with a little addition). This was my first approach: let ...
1 vote
1 answer
1k views

Adding items in the nested array of React state

I'm trying to add new items to an array of an object that resides in another object of a state. Pretty nested. So I tried the following way... // The initial data [options, setOptions] = useState({ ...
648 votes
19 answers
806k views

How to iterate over a JavaScript object?

I have an object in JavaScript: { abc: '...', bca: '...', zzz: '...', xxx: '...', ccc: '...', // ... } I want to use a for loop to get its properties. And I want to iterate ...
2 votes
4 answers
5k views

console.log returns [Object] when object is in multiple other objects [duplicate]

When I have a lot of objects together and I run it using nodejs in cmd It says the [Object] instead of the actual contents of the object. here is an example from my command prompt myObject = { '...
0 votes
1 answer
290 views

Use unknown key in the v-model in vue js for loop

I have a dynamically made object of facets. An example of the data could be: facets: { type: ['type1', 'type2', 'type3'], color: ['color1', 'color2'] } I also have an empty object for filters....
0 votes
2 answers
29 views

How to filter an array which is inside an object which has other details as well

I have an object const object = { name:'XYZ', Others: 'XYZ', numbers:[2,3,4,5,6,5] } I want to filter numbers array which is inside the object and return the object with filtered array like this ...
14 votes
2 answers
16k views

Error in accessor property: can't redefine non-configurable property 'status'

I'm trying to define an object and create an accessor property for it. HTML: <input type='hidden' id='crudMode' value='Create' /> JavaScript: crudMode = { create: "Create", read: "Read"...
1 vote
1 answer
41 views

How to prevent function contructor arrays from being edited via get methods in JavaScript?

I have this code function State(){ const SecretState = { name: 'bob' } this.getState = () => SecretState; this.setState = (name) => SecretState.name = name; } const m = new State() ...
0 votes
1 answer
39 views

update react state of nested object with array

I want to insert a new object inside the options which is an array property inside the select1 object every time the user clicks on add button, how can I achieve this target, pls reply to this query. ...
0 votes
6 answers
234 views

How to transform an array of [x: x1, y: y1] to an array of numbers where the numbers are stored like [x1, y1, x2, y2....] in javascript?

I have an array which looks like: const arr = [1,2,3,4,5,6] I want to convert this array to look something like const arr2 = [ {x: 1, y, 2}, {x:3, y:4}, {x:5, y:6}] I have tried something like this: ...
0 votes
2 answers
56 views

Create simple object from nested array of objects of arrays

Hi folks I have my json data like this http://json-parser.com/24145c52 I want it to change in this shape (array of objects const model = [ { instituteName:instituteName, ...
0 votes
1 answer
707 views

Arrange Chat Messages By Date

I am working with Vue, but this is a general javascript question. I make a call to an api to get cat messages for a chat UI. The initial call returns an array of objects where each object is a chat ...
-1 votes
2 answers
31 views

Merge objects in array by unique product name

I have object like that const testOb = { ReleaseName: "latest", Products: [ { ProductName: "WIDG", A6Product: true, ProductVersions: ["15.0.0"], ...
-1 votes
1 answer
76 views

Explaining this recursive call to sumil up the values of an object in JavaScript

Hy guys, I recently started learning JavaScript and I got to recursion. I saw a recursive function that I don't really understand what's going on behind the hood, please can some help me by explaining ...
3 votes
3 answers
66 views

How can I create several arrays on each of the values of other array of objects?

So currently I have this array structure: const object = { object1: ["01", "02"], object2: ["item1", "item2", "item3"], object3: ["product1&...
-2 votes
2 answers
645 views

Can i change the position of an item in an object.(Javascript) [duplicate]

I have an object as const details = { firstName: "Priya", age: 26, class: 12, Address: "UP", lastName: "Kumari" } Can I position the "lastName" key ...
1 vote
1 answer
32 views

How to inherit and overide object in JS

I have a react StyleSheet with objects const styleSheet = StyleSheet.create({ picture1: { height: 50, width: 30, alighItems: 'center', } picture2: { height: 50, ...
1 vote
1 answer
98 views

How exactly does javascript set context for objects created from constructor function using the new keyword [duplicate]

Consider the following constructor function having a method logging the context function Foo() { this.logContext1 = () => console.log('logContext1', this); } let foo = new Foo(); foo....

1
18 19
20
21 22
144