Eliminate a string of words from a reply data - angularjs

When I console the response data from an angularjs json response, I found the following words:

$rootScope.myData = res.data;
//the above contains
1. Titles of Variations
2. In Sports
3. Going to Gym
4. My Car Runs Faster
6. Account Setup

I need help removing line 1 and 4 from the json response assigned to myData scope so that it only includes lines 2, 3, and 6. Can you please assist me with this?

Answer №1

Transform a string into an object where line numbers are the keys and exclude specific lines using filter

const text = `Titles of Variations
In Sports
Going to Gym
My Car Runs Faster
Account Setup`;

console.log(text);

const excludedLines = ['1', '4'];

const obj = text.split("\n").reduce((acc, curr, index) => {
  acc[index+1] = curr;
  return acc;
}, {});

const filteredText = Object.entries(obj).filter(([key, _]) => !excludedLines.includes(key)).map((arr) => arr[1]).join("\n");

console.log(filteredText);

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

Learn how to create dynamic graphs using AngularJS with JSON data outputs

.controller('HomeCtrl', function ($scope, $http, $stateParams, $state, FirstHiveService) { var samplelineJsonData = [ { "month": "Jan", "noOfUs ...

Are you struggling with the issue of Function components not being able to be given refs? When you try to access the ref, it just fails. Perhaps you should consider using React.forwardRef

I have implemented the "styled" feature from Material UI to add styles to my components. Right now, I am in the process of cleaning up code to remove console errors. Initially, I encountered this warning message: "Warning: React does not recognize the con ...

Angular selected multiple with initial options

HTML: <select chosen multiple class="form-control" ng-model="model.Skills" ng-options="skills.name.skillName for skills in skills" data-placeholder="Select Skills"> <option value=""></option> </select> $scope.skills = [ ...

Incorporate additional information into the current data series within Lightning Chart

In my React JS application, I have successfully used a point series to create a chart displaying data. However, I am now looking to bind real-time data to the chart. For example, when the chart initially loads with 10 points, I want to continuously receiv ...

Utilize Vuex store in Vue without the need for import statements within components

When working with Vue 2/3 and in an ES6 environment, I often access a Vuex store in an external JS file using the following method: // example.js import { store } from '../store/index'; console.log(store.state.currentUser); While this method w ...

Having trouble retrieving data about my marker through react-leaflet

Hello, I am currently working on accessing information about my marker using React and react-leaflet, which is a library based on Leaflet. I initially tried to utilize useRef, but unfortunately it did not provide the expected results. When attempting to us ...

Exploring the concept of promises in node.js for recursive functions

I'm attempting to use recursive calls in order to fetch data from redis, halting and returning when the members return null. My data is inserted as shown below: SADD parents.<name> <parent1> <parent2> SADD parents.<parent1> & ...

Adjust the sizes of the points according to the level of zoom

I've been working on creating a dynamic map in d3.js that displays US Science funding agencies as points, with their sizes scaling based on zoom level. I referred to this starter kit for guidance. While there are other solutions out there, they often ...

Mongoose is encountering issues with error handling due to the 'useUnifiedTopology: true' pass option

Recently, I discovered that by using the 'useUnifiedTopology: true' option in Mongoose, it eliminates the emission of an error if there are issues with the connection. For instance: mongoose.connect(DB, { useNewUrlParser: true, useCreateInde ...

Display refined outcomes on the search results page

In my app, the main feature is a search box on the homepage. Users can input their search queries and upon submission, they are redirected to a result page displaying the relevant results along with filtering options. The filtering functionality allows use ...

Sending two arguments to an Express Mongoose API in order to fetch a singular outcome

I'm currently exploring the world of developing APIs using Express and Mongoose. Setting up basic endpoints for get, post, put has been a breeze so far. Now, I'm eager to create an endpoint where I can pass two parameters to search a collection ...

Updating website links in real time with the power of jquery

Is there a way to dynamically change the parameter of a link? For example: Link1 Link2 Link3 By default, their URL is ?item=text, so link1 would be href="?item=link1", etc. But when I click on link1, the URLs of link2 and link3 should change to include ...

Double-click required to toggle button

Here is the code snippet for controlling an LED using a web page. The script, linked to Python, effectively controls the LED. However, there is an issue where the button toggles to the right side (ON position) only after a double click. Upon first click ...

Exploring the ng-annotate and resolve features within the ui-router framework

Having an issue with my resolve methods not receiving their injected services. Here is a snippet of my code: (function () { 'use strict'; angular.module('sapphire.sample-limits').config(routes); function routes($stateProv ...

Navigating and exploring data stored in a mongoose database

Currently, I am attempting to filter data based on a specific id (bWYqm6-Oo) and dates between 2019-09-19 and 2019-09-22. The desired result should return the first three items from the database. However, my current query is returning an empty array. I wou ...

What is the best way to calculate the total of values in a JavaScript object?

In my array, I have a list of items with prices that I am attempting to sum up. Here is how it appears in the Chrome developer tools: (3) [{…}, {…}, {…}]0: {ID: 1, ProductName: " New phone 1", Price: "€ 600"}1: {ID: 3, ProductNa ...

Adding a class in Javascript if its parent element already has a class

I am trying to assign a second class to a div if one of its parent elements has a specific class. Here is the approach I took: var elements = document.querySelectorAll('h1,h2,h3,h4,p'); //SELECT ALL ELEMENTS for (var i = 0; i < elements.lengt ...

Merging and Reorganizing files using Gulp based on Folder names

In my gulpfile.js, I am attempting to configure a setup that concatenates all .js files located in the src/js folder and names them based on their parent folder. Here is an example of the folder structure: project | +-assets | | | +-app.min.js | | | +-ve ...

Change the function to utilize an HTML class rather than an ID

I am currently working on a resize image function that requires the ID of a file input element as an input. The function takes the image in the form and outputs a resized canvas of the image. However, I recently made changes to the form structure from a st ...

Exploring the functionality of uiRouter using the requirejs framework

I've been struggling with a problem for a while now and haven't found any solutions in other posts related to testing uiRouter with requirejs. I have a basic controller set up that uses $state.go to switch states when a button is clicked. runsCo ...