By Rambabu Bommisetti

2018-02-13 13:43:13 8 Comments

My Code Scenario is:

var Employees= [{name:"Ram",htno:1245},{name:"mohan",htno:1246},

var seletedEmployees= [{name:"mohan"},{name:"ranga"}];

var employeesdataAfterremoveSelected = [?];


@Rambabu Bommisetti 2018-03-06 13:53:28

var Employees= [{name:"Ram",htno:1245},{name:"mohan",htno:1246}, {name:"madhu",htno:1247},{name:"ranga",htno:1248}]

var seletedEmployees= [{name:"mohan"},{name:"ranga"}];

var employeesdataAfterremoveSelected = Employees.filter(function(val,index) { console.log( return !( { return; }).indexOf(; });

@Tomasz BubaƂa 2018-02-13 13:51:01

You can store selected employees names in an array and then filter Employees array and check if employee's name is in this array:

var employees= [{name:"Ram",htno:1245},{name:"mohan",htno:1246},{name:"madhu",htno:1247},{name:"ranga",htno:1248}]
var selectedEmployees= ["mohan","ranga"];
var result = employees.filter(emp => selectedEmployees.includes(;

To programatically get array of strings instead array of objects, you can use map:

var seletedEmployees= [{name:"mohan"},{name:"ranga"}].map(emp =>;

@zb22 2018-02-13 13:52:59

You can try this:

var Employees = [{name:"Ram",htno:1245},{name:"mohan",htno:1246},

var seletedEmployees = [{name:"mohan"},{name:"ranga"}];

var employeesdataAfterremoveSelected = Employees.filter(name => {
  return ( !== seletedEmployees[0].name && !== seletedEmployees[1].name)


@Rambabu Bommisetti 2018-02-14 07:56:17

if i want to remove one more element instead of var seletedEmployees = [{name:"mohan"},{name:"ranga"}]; i want to delete var seletedEmployees = [{name:"mohan"},{name:"ranga"},{name:"Rambabu"}]; how can I achieve without hard coded inde values as [0] , [1] ....

@zb22 2018-02-15 10:05:45

you can do this then:

@digital-pollution 2018-02-13 13:55:47

You can use the filter method, something like below (not tested)

var Employees = [{name:"Ram",htno:1245}, {name:"mohan",htno:1246}]

var SelectedEmployess = [{name:"Ram",htno:1245}]

// filter the items from the invalid list, out of the complete list
    var employeesdataAfterremoveSelected = Employees.filter(( => {
    return !SelectedEmployess.has(;

// get a Set of the distinct, valid items
var validItems = new Set(employeesdataAfterremoveSelected);

@trichetriche 2018-02-13 13:55:05

Here is a one liner, decomposed to explain :

// Start by filtering the first array on a condition.
employeesdataAfterremoveSelected = Employees.filter(
  // Map the array of selected employees to only return the name
  e => =>
    // use the includes function to check if the name is in the array

In one line :

employeesdataAfterremoveSelected = Employees.filter(e => =>;

@Akbar Badhusha 2018-02-13 13:54:16

From the code you have given above i think this might work

$.each(student, function(key, value){
   if(matchedvalues.indexOf( < 0)

Related Questions

Sponsored Content

58 Answered Questions

[SOLVED] How do I correctly clone a JavaScript object?

45 Answered Questions

30 Answered Questions

[SOLVED] How to append something to an array?

76 Answered Questions

[SOLVED] How do I remove a particular element from an array in JavaScript?

  • 2011-04-23 22:17:18
  • Walker
  • 5510301 View
  • 6835 Score
  • 76 Answer
  • Tags:   javascript arrays

33 Answered Questions

[SOLVED] How do I return the response from an asynchronous call?

43 Answered Questions

[SOLVED] How to check if an object is an array?

35 Answered Questions

[SOLVED] Compare two dates with JavaScript

36 Answered Questions

[SOLVED] How do I remove a property from a JavaScript object?

59 Answered Questions

[SOLVED] How can I merge properties of two JavaScript objects dynamically?

39 Answered Questions

[SOLVED] Sort array of objects by string property value

Sponsored Content