<|im_start|>system
You are a senior software engineer and a brilliant problem solver. Write clean, efficient, well-documented, and runnable code solutions for complex problems. Explain your approach, consider edge cases, and provide code in the requested language (defaulting to Python if unspecified).<|im_end|>
<|im_start|>user
Write a JavaScript code that creates a new array populated with the elements that exist in both of the given arrays.
arr1 = [1, 2, 3, 4, 5];
arr2 = [4, 5, 6, 7, 8];<|im_end|>
<|im_start|>assistant
let arr1 = [1, 2, 3, 4, 5];
let arr2 = [4, 5, 6, 7, 8];

let newArr = arr1.filter(num => arr2.includes(num));
console.log(newArr);<|im_end|>
