What is the method for retrieving a specific value from an array in AngularJS that can be utilized directly in a JavaScript file?

$scope.login = function () {

    var userLoginData = JSON.parse(localStorage.getItem('userData'));

    userName = (userLoginData.Name)
    console.log(userLoginData);

}

This information is stored in my browser's local storage

[{"Name":"Admin","EmailId":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="29484d444047694e44484045074a4644">[email protected]</a>","password":"Admin","PhoneNo":"9765432108"},{"Name":"testuser2","EmailId":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="592d3c2a2d2c2a3c2b6b193e34383035773a3634">[email protected]</a>","password":"testing","PhoneNo":9871324560},{"Name":"test11","EmailId":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfcbdacccb8e8e8effd8d2ded6d391dcd0d2">[email protected]</a>","password":"test","PhoneNo":9632196321}]

The console output shows,

0: Object { "Name": "Admin", EmailId: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="debfbab3b7b09eb9b3bfb7b2f0bdb1b3">[email protected]</a>", password: "Admin", … }

​ I would like to store the name and password fields in separate variables

Answer №1

Here is the code snippet you can utilize:

$scope.authenticate = function () {

var userCredentials = JSON.parse(localStorage.getItem('userData'));

for(info of userCredentials){
    console.log(info.username);
    console.log(info.password);
 }

}

Answer №2

function signIn() {

        var storedUsers = JSON.parse(localStorage.getItem('usersData'));

        for (var j = 0; j < storedUsers.length; j++) {

         console.log("Email: " + storedUsers[j].email);
          console.log("Password: " + storedUsers[j].password); 

            }

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

Numerous levels of nested closures working alongside synchronous JavaScript code

After receiving an explanatory answer to my previous inquiry, I realize that my initial question lacked sufficient context to address my current situation effectively. Let me present a specific route within my Express application: var eventbriteService = ...

Code timer for HTML redirection

Some time ago, I created this code to display random events on my website. While the code functions well, I now wish to incorporate a timer. I envision that when a user refreshes or enters the page, they will be redirected initially and then redirected ag ...

AngularJS: When the expression is evaluated, it is showing up as the literal {{expression}} text instead of

Resolved: With the help of @Sajeetharan, it was pinpointed that the function GenerateRef was faulty and causing the issue. Although this is a common query, I have not had success in resolving my problem with displaying {{}} to show the outcome. I am atte ...

Updating state based on input from a different component

I am attempting to modify the state of the page index in index.js from the Pagination component, Here is my index.js code: import useSWR from 'swr'; import { useState } from 'react'; const Index = ({ data }) => { const ini ...

Executing an event in Javascript or triggering with Jquery- the process of initiating an event once a value is sent to an input box by Javascript

How do you trigger an event when a JavaScript-passed value is entered into an input box? <!DOCTYPE html> <html> <body> <p>Type something in the text field to activate a function.</p> <input type="text" id="myInput" oninp ...

Visual Studio Code unable to locate source maps for typescript debugging

Looking for some help debugging a basic Hello World TypeScript file. Whenever I try to set a breakpoint, it seems like VS Code is having trouble locating the source map, even though it's saved in the same directory. I'm using Chrome as my browser ...

Tips for updating the value of a $scope variable and running tests with AngularJS Jasmine

For my initial case, the product id should be undefined. var $stateParamsStub = { scheduleId : undefined } Within my controller, I am determining if isUpdate should be true or false. If the productId is undefined, then isUpdate should be false; other ...

When using React.js Material UI's CardActionArea with a flex display, the children elements may not automatically use the full width as expected

Getting straight to the point - I recently experimented with changing the display style property from block to flex, along with setting flexDirection: 'column' for the CardActionArea component. The main goal was to ensure that CardContent maintai ...

Tips for exploring electron without launching additional windows

Is there a way to navigate between HTML pages within the same window without opening multiple windows in Electron? ...

Display the execution duration on an HTML document

Recently, I created a loan calculator using Javascript and now I'm contemplating on incorporating the time taken for the code to execute into the results. My intention is to have the execution time displayed on my HTML page, but I am unsure of how to ...

Methods for adding and deleting checkbox values in a hidden field

I have been attempting to append the values of selected checkboxes to a hidden field. So far, I have only been able to add one checkbox value at a time. Is there a way to append multiple selected checkbox values to a hidden field? function CheckBox_ ...

Choose a specific example using the class name in nicEdit

Is there a way to select an instance using nicEdit based on its class name rather than just its id? For example: <div class="myInstance1"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed magna dolor, faucibus ac, iaculis non, cursus et ...

Creating Dynamic Input Binding in Vue.js with an Array of Computed Properties

Currently, I am faced with a situation where I need the v-model binding of an input field to be determined by the computed property's returned value. Take a look at the example provided below: <!DOCTYPE html> <html> <head> <scri ...

Assistance with JSONP (Without the use of jQuery)

I've been putting in a lot of effort trying to understand how to make a JSONP request, but all the reference materials I find are full of jQuery examples. I can go through the jQuery source code, but I prefer a straightforward and simple example. I&ap ...

The path('/') in $rootScope is not functioning properly

Below is a function called register() that I am working with. <form class="form-auth" ng-submit="register()"> This is how I have defined the register function: $scope.register = function(){ $http.post('/auth/signup', $scope.user).success ...

Loading all assets in advance

Is there a one-size-fits-all method to preload all assets before using them? I need to load various images, audio files, and some .swf files before my application launches. Right now, I load images by creating new <img> elements with the image path a ...

Storing website data for localization purposes on the web platform

I am currently working on a project to develop a website that displays the selected language page upon first visit. The idea is that when a user clicks on a language name, such as French, it will be stored in web/local storage. Then, when the user returns ...

Bizarre Actions of a JavaScript Object

Currently, I am in the process of developing a Multiplayer game using Phaser and Eureca io. My main focus right now is on perfecting the authentication of players and their controls. To achieve this, I have implemented a method on the server that retrieves ...

Tips on managing ajaxStart and ajaxStop events the Angular2 way

I am seeking a way to trigger events similar to JQuery's ajaxStart and ajaxStop. While I found a partial solution on how to set default HTTP headers in Angular 2 here, I have managed to handle the ajaxStart event for now. Does anyone have any soluti ...

When looking at react/17.0.1/umd/react.development.js, it becomes evident that ReactDOM is not defined

I'm currently immersing myself in learning React with the help of React Quickly, written by Azat Mardan, which is based on React v15.5.4. The examples provided in the book typically include two essential files: react.js and react-dom.js, such as in th ...