我正在尝试从数组中获取索引,其中“ Type_”与数组匹配。
数组是这样的:
return this.props.foodWeekPlan.map((course, i) => {
return (
<tr key={i}>
{course.map((meal, j) => (
<td key={j}>
{meal.map((ingredients, k) => (
<p key={k}>{ingredients}</p>
))}
</td>
))}
</tr>
);
});
答案应该是这样的:
['Type_test', 'Type_hello', 'Type_google', 'Type_apple', 'mango', 'orange'];
答案 0 :(得分:-1)
ES6:
const array = ['Type_test', 'Type_hello', 'Type_google', 'Type_apple', 'mango', 'orange'];
const result = array.filter(e => e.startsWith('Type_'));
console.log(result);
ES6之前的版本:
var array = ['Type_test', 'Type_hello', 'Type_google', 'Type_apple', 'mango', 'orange'];
var result = array.filter(function (e) {
return e.substring(0, 5) === 'Type_'
})
console.log(result);