JSFiddle - React, Tailwind, and code Playground

by GregWoods

JavaScript

//cut down list of uom data
var data = [
        {"Id":1,"Name":"Kilogram"},
        {"Id":2,"Name":"Gram"},
        {"Id":3,"Name":"Microgram"},
        {"Id":4,"Name":"Milligram"},
        {"Id":5,"Name":"Metric Ton"},
        {"Id":6,"Name":"Pound"},
        {"Id":7,"Name":"Ton (US, Short)"},
        {"Id":8,"Name":"Ounce"},
        {"Id":232,"Name":"Ton (UK, Long)"}
    ];


function removeUoms(arrayOfUoms, uomIdsToBeExcluded) {
	return jQuery.grep(arrayOfUoms, function (el) {
		var inArr = jQuery.inArray(el.Id, [1,3]);
		return (inArr == -1);
	});
}

var after = removeUoms(data, [1,3]);

console.log(after);

//test what happens to an array when you remove all items with splice
// I'd hope it results in an empty array
var testArray = [1]
console.log(testArray);
testArray.splice(0,1);
console.log(testArray);
//it does return an empty array