我怎样才能只从数组中获取值 ([type: string]: string)

How can i only get the values from a array ([type: string]: string)

我有一个这样输入的数组:

array: {
    [type: string]: string;
}

并且我想在没有任何键的情况下从中获取所有值。

我尝试通过多种方式获取它,但都没有..

这是一个代码示例:

const array: {
    [field: string]: string
} = {};

array['someProperty1'] = 'value1'
array['somePropert2'] = 'value2'

这里如果我控制台日志 array 我得到

{
    array: {
        someProperty1: 'value1',
        someProperty2: 'value2'
}
}

我只想得到一个数组 ['value1', 'value2']

你所说的 'array' 在技术上不是数组,而是字典,但你可以使用 Object.values:

轻松获取值
const realArray = Object.values(array);