get
Like lodash's get.
Demo
vue
<script setup lang="ts">
import { get } from '.'
const data = [
{ one: 1 },
{
two: 2,
three: {
data: 3,
},
other: [
4,
{ value: 5 },
],
},
]
const input = ref('[0].one')
const show = computed(() => get(data, input.value))
</script>
<template>
<div>
<p font-bold text-xl>
Try it!
</p>
<p>data:</p>
<pre>
{{ data }}
</pre>
<input v-model="input" input>
<p>{{ show }}</p>
</div>
</template>Try it!
data:
[
{
"one": 1
},
{
"two": 2,
"three": {
"data": 3
},
"other": [
4,
{
"value": 5
}
]
}
]
1
Type Declarations
Details
ts
/**
* @example
*
* ```js
* get({ friends: [{ name: 'me' }] }, 'friends[0].name') // -> 'me'
* get([{hello: 'world'}], '[0].hello') // -> 'world'
* ```
*
* @see {@link https://s3xysteak.github.io/fnclip/functions/object/get/}
*/
export declare function get<TDefault = unknown>(value: any, path: string, defaultValue?: TDefault): TDefault;