Answers for "array filter key value javascript"

PHP
6

array filter use key

$my_array = ['foo' => 1, 'hello' => 'world'];
$allowed  = ['foo', 'bar'];
$filtered = array_filter(
    $my_array,
    function ($key) use ($allowed) {
        return in_array($key, $allowed);
    },
    ARRAY_FILTER_USE_KEY
);
Posted by: Guest on November-04-2020
0

does filter change original array

Note: filter() does not change the original array.
Posted by: Guest on July-25-2020

Code answers related to "array filter key value javascript"

Browse Popular Code Answers by Language