找到关于面向对象编程的9301 篇文章
404 次浏览
假设我们有两个这样的数组:const meals = ["breakfast", "lunch", "dinner"]; const ingredients = [ ["eggs", "yogurt", "toast"], ["falafel", "mushrooms", "fries"], ["pasta", "cheese"] ];我们需要编写一个 JavaScript 函数,它接收这两个数组,并将第二个数组中的子数组映射到第一个数组的相应字符串。因此,上述数组的输出应如下所示:const output = { "breakfast" : ["eggs", "yogurt", "toast"], "lunch": ["falafel", "mushrooms", "fries"], "dinner": ["pasta", "cheese"] };示例此代码将如下所示:const meals = ["breakfast", "lunch", "dinner"]; const ingredients ... 阅读更多
196 次浏览
我们需要编写一个 JavaScript 函数,它接收两个长度相同的数组。然后,我们的函数应该组合数组的对应元素,以形成输出数组的对应子数组,最后返回输出数组。如果这两个数组是:const arr1 = ['a', 'b', 'c']; const arr2 = [1, 2, 3];那么输出应该是:const output = [ ['a', 1], ['b', 2], ['c', 3] ];示例此代码将如下所示:const arr1 = ['a', 'b', 'c']; const arr2 = [1, 2, 3]; const combineCorresponding = (arr1 = [], arr2 ... 阅读更多
1K+ 次浏览
假设我们有一个这样的嵌套对象数组:const arr = [ { value: 'some value' }, { array: [ { value: 'some value' }, { array: [ { value: 'some value' }, { value: 'some value' }, ], }, { value: 'some value' }, ], }, { value: 'some value' }, ];我们需要编写一个 JavaScript 函数,它接收这样一个对象,并返回所有这些对象的“value”属性值的数组。因此,对于上述数组,输出应该如下所示:const output = ['some value', 'some value', 'some value', 'some value', 'some value'];示例此代码将如下所示:const arr = [ ... 阅读更多
409 次浏览
假设我们有一个这样的嵌套数组:const arr = ['zero', ['one', 'two' , 'three', ['four', ['five', 'six', ['seven']]]]];我们需要编写一个 JavaScript 函数,它接收一个嵌套数组。然后,我们的函数应该返回一个字符串,该字符串包含所有数组元素,这些元素用分号 (';') 连接。因此,对于上述数组,输出应如下所示:const output = 'zero;one;two;three;four;five;six;seven;';示例此代码将如下所示:const arr = ['zero', ['one', 'two' , 'three', ['four', ['five', 'six', ['seven']]]]]; const buildString = (arr = [], res = '') => { for(let i = 0; i < arr.length; ... 阅读更多
265 次浏览
假设我们有一个这样的对象数组:const arr = [ { id : "23", name : "Item 1", isActive : true}, { id : "25", name : "Item 2", isActive : false}, { id : "26", name : "Item 3", isActive : false}, { id : "30", name : "Item 4", isActive : true}, { id : "45", name : "Item 5", isActive : true} ];我们需要编写一个 JavaScript 函数,它接收这样一个对象,并返回所有这些对象的“id”属性值的数组。 ... 阅读更多
306 次浏览
我们需要编写一个 JavaScript 函数,它将文字值的数组作为第一个参数,并将字符串作为第二个参数。我们的函数应按字母顺序对数组进行排序,但将作为第二个参数提供的字符串(如果存在于数组中)保留为第一个元素,而不管其文本内容如何。示例此代码将如下所示:const arr = ["Apple", "Orange", "Grapes", "Pineapple", "None", "Dates"]; const sortKeepingConstants = (arr = [], text = '') => { const sorter = (a, b) => { return (b === text) - (a ... 阅读更多
722 次浏览
假设我们有两个这样的子 JSON 对象数组和父 JSON 对象数组:const child = [{ id: 1, name: 'somename', parent: { id: 2 }, }, { id: 2, name: 'some child name', parent: { id: 4 } }]; const parent = [{ id: 1, parentName: 'The first', child: {} }, { id: 2, parentName: 'The second', child: {} }, { id: 3, parentName: 'The third', child: {} }, { id: 4, parentName: 'The ... 阅读更多
781 次浏览
假设我们有一个这样的对象数组:const arr = [ {"Date":"2014", "Amount1":90, "Amount2":800}, {"Date":"2015", "Amount1":110, "Amount2":300}, {"Date":"2016", "Amount1":3000, "Amount2":500} ];我们需要编写一个 JavaScript 函数,它接收这样一个数组,并将此数组映射到另一个数组,该数组包含数组而不是对象。因此,最终数组应如下所示:const output = [ ['2014', 90, 800], ['2015', 110, 300], ['2016', 3000, 500] ];示例此代码将如下所示:const arr = [ {"Date":"2014", "Amount1":90, "Amount2":800}, {"Date":"2015", "Amount1":110, "Amount2":300}, {"Date":"2016", "Amount1":3000, "Amount2":500} ]; const arrify ... 阅读更多
806 次浏览
假设我们有一个用逗号分隔的字符串,例如:const str = "a, b, c, d , e";我们需要编写一个 JavaScript 函数,接收这样的字符串,去除其中的所有空格,然后将字符串分割成字面量的数组并返回该数组。示例代码如下:const str = "a, b, c, d , e"; const shedAndSplit = (str = '') => { const removeSpaces = () => { let res = ''; for(let i = 0; i < str.length; ... 阅读更多
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP