Trouble with _.keys function in Firebug - not detecting all items

I currently have a post stored in $scope.mydata within the controller. I pass this data as a parameter to a service that returns a function.

The service looks like:

module.factory('myservice', function () {
    return function servicefunction(mydata) {
        var test = _.keys(mydata).length;
        console.log("mydata", mydata);
        console.log("test", test);

Using Firebug in Firefox, it shows me that mydata contains:

Object { $$state={...},  angularCollection=false,  $object={...},  more...}

and the test result is 5.

However, when I try this code:

module.factory('myservice', function () {
    return function servicefunction(mydata) {
        var test = _.keys(mydata.$$state).length;
        console.log("mydata", mydata.$$state);
        console.log("test", test);

Firebug now displays Object { status=0} with a status and value []. I am trying to access that value. The test result is 1 for the status.

I'm puzzled as to why the test using _.keys finds the status but not the value?

Answer №1

It appears that you are attempting to retrieve a property (value) which is inherited from the mydata.$$state object's prototype. When using _.keys, this will not include value.

This inheritance may be temporary because the property is currently empty, and it will become a direct property once it has a value.

Instead of complicating things, why not just access it directly like this: mydata.$$state.value? This should work whether the property is inherited or not.

If this solution still doesn't resolve your issue, please provide more details about your data so I can better assist you in solving the problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Unleashing the power of perpetual testing: A guide to seamlessly integrating Protractor with SauceL

My website has a web server running protractor tests, and I am looking to set up continuous testing with Saucelabs. According to Saucelabs, all I need to do is add my Saucelabs username and key to the conf.js file of Protractor. Would using cron or anothe ...

Uploading files in React.js using Yii2 API

I am working with react.js (version 15) and I need to upload files using yii2 api. Here is my code: My component in react: import React, { Component } from 'react'; import Header from './Heaader'; /* global $ */ class New ...

getting data from JavaScript function by making an asynchronous request to RESTful API

My current challenge involves calling a JavaScript method that utilizes AJAX to access a REST service and then return the response to the original call. While this may seem straightforward, I have scoured Stack Overflow for answers but haven't found a ...

Create a WebGL object remotely on the server

Exploring potential project ideas, I was curious to see if it's feasible to produce a WebGL scene or object on the server side and then have it rendered on the client. The motivation behind this is that generating a scene typically involves utilizing ...

Implementing a 3D cylinder chart with ReactJS using Highcharts

I've been attempting to incorporate a cylinder 3D chart into my react component, but I keep encountering this error message. Error: Highcharts error #17: www.highcharts.com/errors/17/?missingModuleFor=cylinder missingModuleFor: cylinder The code in ...

What is the method for showcasing an image before it has been uploaded?

I must start by apologizing for my English, as I am not the most fluent speaker. Here's where I'm facing a dilemma: I have created an application that allows users to edit questions for a game. These questions are stored on a server and can be ...

Creating sequential numbers using jQuery

Recently, I worked on a script (credit to Chyno Deluxe) that generates a list of menu items based on what is written in the input box. However, I now have a new requirement which involves generating a sequence of numbers to be added continuously. Here is ...

Unable to convert multiple strings into integers using parseInt

Though seemingly straightforward, I couldn't figure out why I was unable to solve it. I'm attempting to convert a string to an integer from JSON data. It successfully converts the first object, but for some reason fails with the second one: HTM ...

AngularJS ng-disabled not functioning properly when multiple conditions are used with && (and) and || (or) operators in the view

I'm in need of some assistance. I've tried various methods to solve this issue, but I just can't seem to get both parameters working together. Using a single parameter works fine for me. This is my desired outcome: If the selection in my ...

Sharing an object reference outside of a handler, for example, by making it accessible globally

I'm curious about best practices regarding passing references of the socket object outside of a method handler. In the code snippet below, can anyone provide guidance on how to achieve this? io.on('connection', function (socket) { co ...

Is it possible to select a date from the datepicker, or should I move to the next month to find an

Protractor newbie here, attempting to test a date picker with Protractor. My attempt at selecting an available date: this.selectAvailableDate = element(by.css('td[aria-disabled="false"]')); If the desired date is not in the current month, I nee ...

Master the art of managing filenames with JavaScript

Here is a piece of javascript code that I created: fileName = "Report_" + Name + ".csv" var hiddenElement = document.createElement('a'); hiddenElement.href = 'data:attachment/text,' + encodeURI(data); hiddenElement.targ ...

Duplicate the array of objects and make alterations without affecting the original array

I have an array of objects that I need to deep copy and make modifications to each object without altering the original array or its contents. Here is my approach in JavaScript, but I am open to suggestions on a better method. const users = [ { ...

Issue with webpack-dev-server causing it to not reload and build automatically due to configuration error

Currently in my project, I am utilizing the following versions: "webpack": "2.2.1", "webpack-dev-server": "2.4.2" I am looking to create an application that can automatically rebuild when a file is changed using webpack-dev-server live reloading. Within ...

Getting command line argument parameters in React can be achieved by utilizing the `process.argv`

Is there a way to retrieve command line argument parameters in React? I currently have a React codebase that is utilizing Webpack. When running the following commands - npm run build -- --configuration=dev or npm run build -- --configuration=qa I need t ...

What is the method to update an element when any of the items in an array is marked as "Confirmed"?

{submissions && submissions.files_set.map((el) => { if (el.confirmed_status === null) { return <DataToConfirm />; } else if (el.confirmed_status === "CONFIRMED") { return <DataSent />; } })} This ...

Error in defining class variable within the constructor not found

Just started delving into CoffeeScript and facing a challenge. In my code snippet below, I initialize WebSocketServer with a number as the first argument and a function as the second argument. However, when the websocket receives a message, @msgHandler sud ...

Develop a revolutionary web tool integrating Node.js, MongoDb, and D3.js for unparalleled efficiency and functionality

I am exploring the creation of a web application that will showcase data gathered from various websites. To achieve this, my plan involves automating the process of data collection through web scraping. After collecting the data from these sites, I will fo ...

Exploring the realm of Angular templating and routing combined with the power

Currently, I am in the process of developing my very first Angular website that involves templating and routing. My goal is to have an image on the page that spans the entire window size minus 70 pixels. //Using Jquery (This particular section functions ...

What could be causing the malfunction of useEffect() in my script?

const [isOpen, setIsOpen] = useState(false); useEffect(() => { if (!token) { return <Navigate to="/auth/login"/> } getMe(token) }, [token, getMe]) return ( <RootStyle> <DashboardNavbar onOpenSi ...