Updating Data in Angular Using JSON Values

I have a question about manipulating JSON Objects in Angular. Specifically, I am looking to replace all semicolons ";" with an empty string from a specific key.

$scope.users = data; 

My goal is to iterate through the object and only replace values in the following key:

$scope.users[i]['pic'];

Any help or guidance on this matter would be greatly appreciated. Thank you!

Answer №1

$scope.users=[{'pic':'df;gd;'},{'pic':'adfgadfgadfgad;adf   fdag;'},{'pic':'adfdff; ;;;'}];


angular.forEach($scope.users,function(value, key) {
value.pic= value.pic.replace(/;/g ,'');
},{});

http://jsfiddle.net/fp5roLae/

Answer №2

const userList = [{"id":"1234","photo":"profile_image.png;"},{"id":"5678","photo":"profile_pic.png;"}]

for(let user in userList){ 
    userList[user]['photo'] = userList[user]['photo'].replace(";", "");    
}

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

React app version displaying incorrect links to CSS and JS files

I have been immersed in a React project called Simple-portfolio, you can find the GitHub repository here: https://github.com/Devang47/simple-portfolio and the live site at this URL: While everything works smoothly on the development server, I encountered ...

Parsing the JSON string and incorporating it into an SQL query prior to sending the results back to the Client Application

I am currently in the process of developing a WCF REST service that involves querying a SQL database using ID's received from a Client Application. The workflow includes obtaining ID's from a multi-line textbox, serializing them, and then sending ...

What is the best way to execute a function once all asynchronous functions within a loop have finished?

Currently, I am facing an issue with my NodeJS forEach loop where I iterate over a series of keys and then asynchronously retrieve their values from Redis. The problem arises because the data retrieval is asynchronous, causing my array to not be fully popu ...

Can Jest be utilized to write unit tests for the fs.readFile() function in Node.js?

As a newcomer to Jest unit testing, I have been pondering the possibility of using Jest to test Node.js file system modules. At present, I have a text file containing a short poem, and the viewText function displays the poem in my terminal through console ...

Connect an Angular Service object to a Controller's Scope and keeping it in sync

I am facing an issue with the interaction between my EmployeeService and EmployeeController. The service contains a specific object which I bind to the controller's scope: app.controller('EmployeeController', function($scope, EmployeeServic ...

Exploring Javascript: Understanding the Contrast Between Function and Class

In June 2015, with the introduction of ECMAScript 6, a new syntax for Javascript classes was unveiled. The new syntax is exemplified by the following code snippet: class Polygon { constructor(width, height) { this.width = width; thi ...

What is the method for implementing two-way binding on a checkbox in Angular?

Within my accordion, I have a series of options in the form of checkboxes. Users are able to select these checkboxes, but I am seeking a way to pre-select certain checkboxes based on specific conditions. The challenge arises when these conditions are deter ...

The module instantiation in AngularJS encountered an error

Currently learning AngularJS and attempting to develop an authentication service, but encountering an error. Error: [$injector:modulerr] Failed to create module flujoDeCaja: [$injector:modulerr] Module auth failed to instantiate: [$injector:nomod] Module ...

Conditional jQuery actions based on the selected radio button - utilizing if/else statements

This task seemed simple at first, but I quickly realized it's more challenging than expected. Apologies in advance, as Javascript is not my strong suit. My goal is to have the main button (Get Your New Rate) perform different actions based on whether ...

Transform the JavaScript object array into a PHP array by looping through it

I'm currently working on a PHP/Laravel endpoint and I have data that needs to be converted into a PHP array so that I can iterate through the members. However, despite my efforts, I am unable to use json_decode() on it successfully. { levels: [ {r ...

Skipping beforeRouteLeave in VueJS

In my Vue SPA, there is a component where I am using the beforeRouteLeave guard to prevent accidental page exits. However, within this component, I occasionally make an ajax request that, upon successful completion, needs to redirect the user to another lo ...

The Bootstrap tab feature is malfunctioning when a tab is using data-target instead of href

While developing bootstrap tabs for an Angular app, I decided to use the data-target attribute instead of the href attribute to avoid any interference with routes. Here's a snippet of how I structured the tabs: <ul class="nav nav-tabs" id="myTab"& ...

Ways to determine if content is visible within a div

My website contains a script that brings in content from an ad network and displays it within a div element. Unfortunately, this particular ad network only fills ads 80% of the time, leaving the remaining 20% of the time without any ads to display. This la ...

Tips for resolving the problem when encountering the "undefined data" issue in the success callback of an AJAX request

I am facing an issue with my JSP page where I have a button that calls an Ajax method named "sendmail()" upon click. The send mail API is in the Controller, and I am trying to display an alert message in the Ajax success function using data.message, but it ...

Simultaneously Operating Node and Apache Servers

Currently, I am developing a project that enables users to track energy usage. The main dashboard is a sleek web app that heavily relies on javascript and ajax. At the moment, the server operates on apache with php; however, my plan is to integrate node.js ...

The issue with Node.js router failing to process delete requests

My Node.js router is handling all methods well except for the DELETE method. I can't figure out why the delete request does not reach the router. The AJAX request seems to be functioning correctly. AJAX request: function ajaxHelper(url, onSuccessAr ...

The URL is not appearing in the browser's address bar

Below is the code I am using for ajax requests: // JavaScript Document function createTeam() { var name=document.getElementById("name").value; if(name==null || name==""){ var div3 = document.getElementById("errorMessage"); var text ...

Discovering the exact latitude and longitude coordinates along a specific route using Google Maps

I've encountered a problem with finding the latitude and longitude along a given route using Google Maps DirectionsService. I have a JSON dataset containing latitude, longitude, and price details. My goal is to plot markers on the map and determine wh ...

Deleting a specific key from a JavaScript Object

I seem to be struggling with the right terminology here, but I'm hoping someone can help me out: My routine returns a JSON array that works perfectly. However, I need to perform some calculations based on the data passed. To accomplish this, I have ...

Utilize JavaScript to import an XML file from a specific directory

I am trying to use JavaScript to load an XML file. Below is the code I am using to load the XML file when it is in the same folder: if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHtt ...