【发布时间】:2020-09-13 20:32:48
【问题描述】:
我是 javascript 新手,所以我什至不知道从哪里开始。请有人帮助我。
我有这个成分清单:
const Ingris = [
{
val: "onion,",
amount: "1",
},
{
val: "paprika",
amount: "½ tsp",
},
{
val: "yogurt",
amount: "1/2 Cup",
},
{
val: "fine sea salt",
amount: "½ tsp ",
},
];
我想根据以下这些变量对它们进行分类:
var spices = ["paprika", "parsley", "peppermint", "poppy seed", "rosemary"];
var meats = ["steak", "ground beef", "stewing beef", "roast beef", "ribs"];
var dairy = ["milk", "eggs", "cheese", "yogurt"];
var produce = ["peppers", "radishes", "onions", "tomatoes"];
这是我想要获得的:
// desired output:
const ShoppingList = [
{
produceOutput: [
{
val: "garlic, minced",
amount: "8 cloves ",
},
],
spicesOutput: [
{
val: "paprika",
amount: "½ tsp ",
},
{
val: "onion",
amount: "1",
},
],
NoCategoryOutput: [
{
val: "fine sea salt",
amount: "½ tsp",
},
],
},
];
【问题讨论】:
-
我只是想为自己的个人项目学习 JavaScript。如果您愿意帮助我,我将不胜感激
-
这里有一种惯例,您会展示您尝试过但遇到问题的代码,以便我们查看、修复或提出替代方案。
-
@我会这样做,如果我知道怎么做的话。如果我什至不知道该怎么做,我就无法发布我尝试过的任何内容
标签: javascript arrays sorting object javascript-objects