Javascript 使用rxjs从具有特定属性的对象数组中获取对象数组

Javascript 使用rxjs从具有特定属性的对象数组中获取对象数组,javascript,rxjs,Javascript,Rxjs,我有一个数据库,它是一个对象数组。它看起来像这样: export const BIKES: Bike[] = [ { id: 1, imgUrl: 'https://cyclingmagazine.ca/wp-content/uploads/2018/10/Krypton_A18_2016_red_ultegra_16_1.jpg', price: 28000, discount: 71, main: true, shop: 'Ca

我有一个数据库,它是一个对象数组。它看起来像这样:

export const BIKES: Bike[] = [
  {
    id: 1,
    imgUrl:
      'https://cyclingmagazine.ca/wp-content/uploads/2018/10/Krypton_A18_2016_red_ultegra_16_1.jpg',
    price: 28000,
    discount: 71,
    main: true,
    shop: 'Canada Bike',
    name: 'Argon 18',`
},
{
    id: 2,
    imgUrl:
      'https://cyclingmagazine.ca/wp-content/uploads/2018/03/etap.shadowpsd_2048x.png',
    price: 7900,
    discount: 41,
    main: false,
    shop: 'Amazon',
    name: 'Aquila Cycles',
}

我想订阅由两个属性“name”和“shop”及其值组成的对象数组。

可以使用
数组实现。map

const result = BIKES.map(({name, shop}) => ({ name, shop }));
console.log(result);


你在问如何更改
Bike
接口以获取新的obejcts数组?我不理解这个问题。是否要订阅具有2个键的对象数组?那是什么,一个新阵列?“订阅数组”是什么意思?另外,这是您的数据库(Mongo显然是?),您正在谈论RxJS和Angular,它们在前端?我很抱歉,lostIt不清楚您在问什么。如果您使用的是RxJs或其他地方的流,那么它可能还有一个
map
方法,其作用应该非常类似。
const result = BIKES.map((item) => {
  return {
    name: item.name,
    shop: item.shop
  };
});
console.log(result);