const bible = [
{
"id":1001001,
"Book":"Genesis",
"Chapter":1,
"Verse":1,
"Text":"In the beginning God created the heaven and the earth."
},
{
"id":1001002,
"Book":"Genesis",
"Chapter":1,
"Verse":2,
"Text":"And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters."
},
{
"id":1001003,
"Book":"Genesis",
"Chapter":1,
"Verse":3,
"Text":"And God said, Let there be light: and there was light."
},
{
"id":1001004,
"Book":"Exodus",
"Chapter":1,
"Verse":4,
"Text":"And God saw the light, that it was good: and God divided the light from the darkness."
},
{
"id":1001005,
"Book":"Exodus",
"Chapter":1,
"Verse":5,
"Text":"And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day."
},
{
"id":1001006,
"Book":"Genesis",
"Chapter":1,
"Verse":6,
"Text":"And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters."
},
{
"id":1001007,
"Book":"Revelation",
"Chapter":1,
"Verse":7,
"Text":"And God made the firmament, and divided the waters which were under the firmament from the waters which were above the firmament: and it was so."
},
{
"id":1001008,
"Book":"Revelation",
"Chapter":1,
"Verse":8,
"Text":"And God called the firmament Heaven. And the evening and the morning were the second day."
},
{
"id":1001009,
"Book":"Genesis",
"Chapter":1,
"Verse":9,
"Text":"And God said, Let the waters under the heaven be gathered together unto one place, and let the dry land appear: and it was so."
},
{
"id":1001010,
"Book":"Genesis",
"Chapter":1,
"Verse":10,
"Text":"And God called the dry land Earth; and the gathering together of the waters called he Seas: and God saw that it was good."
}
]
How can i return an array with no duplicate bible.Book ?
3 Réponses :
Vous pouvez utiliser P> Array #Filter code> avec tableau # FINTIDEX code> . const bible = [
{
"id":1001001,
"Book":"Genesis",
"Chapter":1,
"Verse":1,
"Text":"In the beginning God created the heaven and the earth."
},
{
"id":1001002,
"Book":"Genesis",
"Chapter":1,
"Verse":2,
"Text":"And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters."
},
{
"id":1001003,
"Book":"Genesis",
"Chapter":1,
"Verse":3,
"Text":"And God said, Let there be light: and there was light."
},
{
"id":1001004,
"Book":"Exodus",
"Chapter":1,
"Verse":4,
"Text":"And God saw the light, that it was good: and God divided the light from the darkness."
},
{
"id":1001005,
"Book":"Exodus",
"Chapter":1,
"Verse":5,
"Text":"And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day."
},
{
"id":1001006,
"Book":"Genesis",
"Chapter":1,
"Verse":6,
"Text":"And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters."
},
{
"id":1001007,
"Book":"Revelation",
"Chapter":1,
"Verse":7,
"Text":"And God made the firmament, and divided the waters which were under the firmament from the waters which were above the firmament: and it was so."
},
{
"id":1001008,
"Book":"Revelation",
"Chapter":1,
"Verse":8,
"Text":"And God called the firmament Heaven. And the evening and the morning were the second day."
},
{
"id":1001009,
"Book":"Genesis",
"Chapter":1,
"Verse":9,
"Text":"And God said, Let the waters under the heaven be gathered together unto one place, and let the dry land appear: and it was so."
},
{
"id":1001010,
"Book":"Genesis",
"Chapter":1,
"Verse":10,
"Text":"And God called the dry land Earth; and the gathering together of the waters called he Seas: and God saw that it was good."
}
];
const res = bible.filter((x,idx)=>bible.findIndex(y=>y.Book===x.Book)===idx);
console.log(res);
Cela ne renvoie qu'une seule fois la genèse. Je veux qu'il retourne tous les objets. mais pas 2 fois la même Bible.Book
@Ilsevandommelen Que voulez-vous dire? Ma réponse filtre tous les autres objets avec la même propriété code> code>. Quelle est l'attente de production?
Const Filter = [{"ID": 1001001, "Book": "Genesis", "Chapitre": 1, "Verse": 1, "Texte": "Au début, Dieu a créé le ciel et la terre." }, {"id": 1001004, "Book": "Exodus", "Chapitre": 1, "Verset": 4, "Texte": "Et Dieu a vu la lumière, que c'était bon: et Dieu a divisé la lumière de l'obscurité. " }]
Genèse unique, une fois l'exode, etc., etc.
@Ilsevandommelen Quel est le problème avec la sortie de ma réponse?
Votre sortie ne me donne qu'un seul objet.
@Ilsevandommelen Il génère un tableau avec 3 objets. Avez-vous dirigé l'extrait?
const bible = [
{
"id":1001001,
Book:"Genesis",
"Chapter":1,
"Verse":1,
"Text":"In the beginning God created the heaven and the earth."
},
{
"id":1001002,
Book:"Genesis",
"Chapter":1,
"Verse":2,
"Text":"And the earth was without form, and void; and darkness was upon the face of the deep. And the Spirit of God moved upon the face of the waters."
},
{
"id":1001003,
Book:"Genesis",
"Chapter":1,
"Verse":3,
"Text":"And God said, Let there be light: and there was light."
},
{
"id":1001004,
Book:"Exodus",
"Chapter":1,
"Verse":4,
"Text":"And God saw the light, that it was good: and God divided the light from the darkness."
},
{
"id":1001005,
Book:"Exodus",
"Chapter":1,
"Verse":5,
"Text":"And God called the light Day, and the darkness he called Night. And the evening and the morning were the first day."
},
{
"id":1001006,
Book:"Genesis",
"Chapter":1,
"Verse":6,
"Text":"And God said, Let there be a firmament in the midst of the waters, and let it divide the waters from the waters."
},
{
"id":1001007,
Book:"Revelation",
"Chapter":1,
"Verse":7,
"Text":"And God made the firmament, and divided the waters which were under the firmament from the waters which were above the firmament: and it was so."
},
{
"id":1001008,
Book:"Revelation",
"Chapter":1,
"Verse":8,
"Text":"And God called the firmament Heaven. And the evening and the morning were the second day."
},
{
"id":1001009,
Book:"Genesis",
"Chapter":1,
"Verse":9,
"Text":"And God said, Let the waters under the heaven be gathered together unto one place, and let the dry land appear: and it was so."
},
{
"id":1001010,
Book:"Genesis",
"Chapter":1,
"Verse":10,
"Text":"And God called the dry land Earth; and the gathering together of the waters called he Seas: and God saw that it was good."
}
];
const filtered = bible.filter((book, index, bible) => !bible.some((book2, index2) => (book.Book === book2.Book) && (index > index2)));
console.log(filtered);Quand je console.log (filtré), cela me donne un tableau vide.
Je l'ai réparé et fait un extrait
Merci beaucoup. C'est ce que je voulais dire.
Utilisation de P> Carte CODE> Pour obtenir la liste des livres et à l'aide de SET CODE> Qui supprimera les duplicats pour vous var bible = [
{ Book: 'Genesis'},
{ Book: 'Exodus'},
{ Book: 'Revelation'},
{ Book: 'Genesis'},
{ Book: 'Exodus'},
{ Book: 'Revelation'},
{ Book: 'Genesis'},
{ Book: 'Exodus'},
{ Book: 'Revelation'},
]
const books = Object.keys(bible.reduce((o, item) => (o[item.Book] = 1, o), {}));
console.log(books);
Cela ne donne que le livre Genesis. J'en ai besoin pour rendre la genèse, l'exode et la révélation
Je ne suis pas sûr de l'endroit où vous ne récupérez qu'un livre.
Pardon. vous avez raison. Merci beaucoup pour votre aide.