新手上路,求教大神的幫忙
是這樣的,小弟最近覺得程式語言好像很有趣,就想來自學一下,不過在練習的時候真的
是挫折重重...絞盡腦汁了一個早上還是不知道該怎麼對陣列做切割。這邊是問題
1、First, declare a variable named myArray and assign it to an empty array.
2、Now populate myArray with two strings:
Put your full name in the first string, and your favorite color in the second.
3、Next, declare a function named cutName. It should expect a parameter name.
cutName should return an array by breaking up the input string into individual
words.
4、Declare a new variable named myInfo and assign it to an empty object litera
l.
Add the following three key-value pairs to myInfo:
Key: fullName
Value: The result of calling cutName on the name string within myArray.
Key: favoriteColor
Value: The color within myArray.
Key: github
Value:If you have a github handle, enter it here as a string. If not, set this
to null instead.
我的程式是這樣的:
var myArray = ["Kobe Bryant","red"];
var github = null
function cutName(name) {
var res = myArray[0].split("");
return res;
}
var myInfo = {
fullName : cutName(myArray[0]),
favoriteColor : myArray[1],
github : github
};
console.log(myInfo);
myInfo後面兩個物件是正確的,但是名字切不出來啊!會變成Array(12)(超崩潰)!到
底為什麼系統會判定成length?有好心大神願意教導小
弟嗎?耐心看完謝謝大家
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 172.58.92.94 (美國)
※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1582318664.A.774.html
※ 編輯: wawalandhoho (172.58.92.94 美國), 02/22/2020 05:08:45
推
02/22 05:51,
4年前
, 1F
02/22 05:51, 1F
→
02/22 05:54,
4年前
, 2F
02/22 05:54, 2F
→
02/22 05:54,
4年前
, 3F
02/22 05:54, 3F
→
02/22 05:55,
4年前
, 4F
02/22 05:55, 4F
推
02/22 09:57,
4年前
, 5F
02/22 09:57, 5F
→
02/22 11:06,
4年前
, 6F
02/22 11:06, 6F
→
02/22 11:06,
4年前
, 7F
02/22 11:06, 7F
→
02/22 11:24,
4年前
, 8F
02/22 11:24, 8F
→
02/22 11:25,
4年前
, 9F
02/22 11:25, 9F
→
02/22 11:26,
4年前
, 10F
02/22 11:26, 10F
→
02/22 11:37,
4年前
, 11F
02/22 11:37, 11F
→
02/22 11:37,
4年前
, 12F
02/22 11:37, 12F
→
02/22 11:39,
4年前
, 13F
02/22 11:39, 13F
→
02/22 11:39,
4年前
, 14F
02/22 11:39, 14F
→
02/22 11:39,
4年前
, 15F
02/22 11:39, 15F
→
02/22 11:45,
4年前
, 16F
02/22 11:45, 16F
→
02/22 11:45,
4年前
, 17F
02/22 11:45, 17F
→
02/22 11:45,
4年前
, 18F
02/22 11:45, 18F
→
02/22 12:01,
4年前
, 19F
02/22 12:01, 19F
→
02/22 12:01,
4年前
, 20F
02/22 12:01, 20F
→
02/22 12:02,
4年前
, 21F
02/22 12:02, 21F
→
02/22 12:36,
4年前
, 22F
02/22 12:36, 22F
→
02/22 12:38,
4年前
, 23F
02/22 12:38, 23F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章