Finds first occurance of el in array, removes it, and returns it, else returns undefined

PHOTO EMBED

Mon Jun 21 2021 15:10:17 GMT+0000 (Coordinated Universal Time)

Saved by @hisam #javascript #vanilla #array

function remove(array, el) {
	const index = array.indexOf(el);
	if (index > -1) {
		const foundEl = array.splice(index, 1);
        return foundEl;
	}
    return undefined;
}
console.log(remove([2,5,9,1,5,8,5], 5))
content_copyCOPY