I am looking for a way to update a value in a list object and assign the new value to the same list object using AngularJS. Can

var dataList = list with 10 rows and 4 columns;

dataList.then(function(data)){
    $scope.mylist = data.data;
}

For example, my list contains a single row like

name:"rajesh";
id:10009;
branch:"dotnet";etc...

I would like to change all instances of "dotnet" to "angular" in the branch column for every row and save the updated object.

So, I am aiming for this output:

name:"rajesh";//1st row
id:100009;
branch:"angular";


name:"sai";//2nd row
id:1004;
branch:"angular";  and so on

Please provide guidance as I am new to AngularJS

Answer №1

Just a heads up, your JavaScript syntax is outdated and it's recommended to upgrade. Moving on, here's an extended version of the code snippet in your original question.

Update

The code provided below differs from what you've mentioned in the comments. If you're seeking a solution, here it is...

        const results = [
            { Name: 'raju', Id: 1009, Branch: 'cse' },
            { Name: 'sai', Id: 1019, Branch: 'ece' },
            { Name: 'nandu', Id: 1089, Branch: 'civil' }
        ];

        const output = results.map(user => {
            user.Name = '****';
            return user;
        });

You can utilize the map function to manipulate your data.

var test = list containing 10 rows with 4 columns;

test.then(function(d)){

    $scope.mylist = d.data.map(function(user) {
        if (user.branch === 'dotnet') {
            user.branch = 'angular';
        }
        return user;
    });    
}

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

Issue with Tablesort functionality in Internet Explorer

When testing the code below in Chrome and Safari, it shows up fine with the ability to sort and search for each row. However, when using IE (Internet Explorer), specifically version 10, the functionality is not working – clicking on the refresh link does ...

Showing subcategories when clicked using only JavaScript

The solution can be found below I have created a dropdown menu that currently shows the submenu on hover using the following CSS: .main-menu ul li:hover > ul { display: block; } However, my design requires the submenu to appear on click and stay visi ...

Error in accessing image paths with Vue.js

Just diving into learning Vue.js and embarking on a project that involves dynamically loading images in various ways. However, upon running npm run dev, I encountered crashed image icons along with this error in the console log: GET http://localhost:8080 ...

In my app.post request in node.js and express, the body object is nowhere to be found

Having an issue with node.js and express, trying to fetch data from a post request originating from an HTML file. However, when I log the request, the req.body object appears empty. I've added a console.log(req.body) at the beginning of my app.post(" ...

Encountering issue: LineChart is not recognized as a constructor, resulting in failure to display chart on webpage

I am struggling with displaying a chart in my HTML file that should show the details of a specific process from the past few minutes. Whenever I try to initialize the chart using google.charts.load('current', {'packages':['line&apo ...

The value of .val() is a combination of various values

I am currently working on a code that involves showing/hiding elements based on the selection of a value in a <select> tag. My next task is to modify it so that the class is added if .val() is equal to not only '16' but also '14' ...

An exploration of the functionality of the String.fromCharCode method when used with a mobile keyboard in an HTML input

I'm looking to retrieve the keyboard key code and translate it into characters. I've been utilizing the String.fromCharCode javascript method, but it seems to only be effective with a computer keyboard and not functioning properly with a mobile k ...

Discovered an issue with AngularJS involving ng-show and ng-if?

Upon my investigation, I have identified multiple issues with angularjs: <div ng-show="['[]']">this should be displayed but it is not working as expected</div> <div ng-show="[]">this should be displayed but it is not working as ...

Generate the Xpath for the mentioned href element to use with Selenium Webdriver

I need help creating the Xpath for a specific href element using Selenium webdriver with only IE browser. The HTML code I am working with is as follows: I am looking to find the Xpath for: . Can someone assist in generating the correct Xpath expression ...

What is the best way to relocate a rotated canvas image without causing any confusion?

Having trouble moving a rotated image properly on a canvas? It seems that the movement is based on the image's coordinate plane, causing unexpected behavior. How can this issue be resolved effectively? Take a look at the draw function below: functio ...

Is it possible to incorporate jQuery into an AngularJS project?

When it comes to testing, AngularJS is a framework that supports test-driven development. However, jQuery does not follow this approach. Is it acceptable to use jQuery within Angular directives or anywhere in AngularJS for manipulating the DOM? This dilemm ...

Jquery Validate doesn't consistently give a positive response

Having a button that triggers the jQuery validation plugin poses an issue where it consistently returns true, except when the fields are left empty. The rules set for validation seem to be disregarded. DEMO http://jsfiddle.net/sw87W/835/ $(document).read ...

Implementing local storage for a specific user in the initial state using React

Hey there, I'm facing an issue with my code. I'm working on a bank project where I need to store a specific user in local storage to avoid errors when the page is reloaded. The problem arises because the initial state of users is an empty array. ...

React Native application crashes on Android 12 and above when run on an emulator

Currently in the process of creating a music application named Wavelet. Listed below are my dependencies: package.json Typically, I debug on an Android 11 emulator; however, when switching to an Android 12 emulator or using my physical device running on A ...

Having trouble shutting down Metro Bundler on Windows?

While working on my React Native development, I regularly use npm start to get things going. However, I've run into an issue recently when trying to stop the process using Ctrl + c. It seems like I can no longer use npm start smoothly: ERROR Metro ...

Limiting the data obtained from the API to extract only the desired values

Using an API, I am retrieving customer information and displaying it in the console. The code snippet used for this operation is: if (this.readyState === 4) { console.log('Body:', this.responseText); } }; This returns a JSON object with v ...

Retrieve each individual element from an array sequentially using jQuery

I am looking to retrieve elements from an array one at a time and only display each element after completing a certain action with the previous one. Here’s an example: var elems = ['Apple','Orange','Banana'], i = 0; ...

Error: npm encountered a socket timeout issue

Setting up a fresh React application in /home/abhijith/Desktop/React/firstReact/myapp. Installing necessary packages. This process may require a few minutes. Installing react, react-dom, and react-scripts along with cra-template... npm ERR! code ERR_SOCK ...

Looping through AJAX requests in JavaScript

I am attempting to make REST API requests in order to retrieve data and display it on a website. Although I have created a for loop to gather the data, I am encountering an issue where the data is not being displayed on the website. Upon checking with th ...

Combining an unlimited amount of elements in an array using JavaScript

Currently, I am facing a challenge while trying to develop an application using Javascript. What I aim to achieve is a webpage that collects input values from a textbox and stores them in an array. Subsequently, I need to create a function that can add t ...