JSFiddle - React, Tailwind, and code Playground

by LyndseyB

Babel + JSX

const obj = (input) => {
	if(!Array.isArray(input)) {
  	throw(`Expected array but received ${typeof input}`);
  }
  
  const data = [...input];
  
  return {
  	get() {
    	return data;
    },
    remove(item) {
    	if(!data.includes(item)) {
      	return null;
      }
      
      const index = data.findIndex((str) => {
      	return str.toLowerCase() === item.toLowerCase();
      });
      
      data.splice(index, 1);
      
      return data;
    }
  }
};

const two = obj(['one', 'two', 'three', 'four', 'five']);
//console.log(two.get());

const list = ['another', 'list'];
const one = obj(list);
one.remove('list');
console.log(one.get());
console.log(list);