а во вкладке "Ошибки" выводит: Uncaught exception: TypeError: Cannot convert 'n' to object ???
|
Попробывал с другим файлом,поставил вместо document.write-console.log,тоже самое.document.write почему-то работает,а console.log-нет.
|
Uncaught exception: TypeError: Cannot convert 'n' to object
Error thrown at line 9, column 1 in file://localhost/C:/Documents%20and%20Settings/пользователь.FFDBB5C125AD474/Рабочий%20стол/ucheba.html: console.log(n[1]); |
В хроме:
Array[4] ucheba.html:6 undefined ucheba.html:7 Uncaught TypeError: Cannot read property '1' of undefined ucheba.html:9 |
document.write выводит в рабочее окно. им конечно можно пользоваться.. но с объектами не удобно или массивами работать невозможно..
а вот консоль как раз подходит вот только почему не выводит, странно!! |
Я с 8 утра мучаюсь...
|
в хроме должно быть что то вроде такого:
![]() |
Array[4]
0: 24 1: 67 2: 46 3: 30 length: 4 __proto__: Array[0] concat: function concat() { [native code] } constructor: function Array() { [native code] } every: function every() { [native code] } filter: function filter() { [native code] } forEach: function forEach() { [native code] } indexOf: function indexOf() { [native code] } join: function join() { [native code] } lastIndexOf: function lastIndexOf() { [native code] } length: 0 map: function map() { [native code] } pop: function pop() { [native code] } push: function push() { [native code] } reduce: function reduce() { [native code] } reduceRight: function reduceRight() { [native code] } reverse: function reverse() { [native code] } shift: function shift() { [native code] } slice: function slice() { [native code] } some: function some() { [native code] } sort: function sort() { [native code] } splice: function splice() { [native code] } toLocaleString: function toLocaleString() { [native code] } toString: function toString() { [native code] } unshift: function unshift() { [native code] } __proto__: Object ucheba.html:6 undefined ucheba.html:7 Uncaught TypeError: Cannot read property '1' of undefined ucheba.html:9 |
да оно и должно быть!
смотрим в код: var array = [24, 67, 46, 30];// создали массив с 4-мя элементами console.log(array); //выведем массив. //представление может чуть другим из за версии браузера!! это не страшно!! //вот хром вывел в консоль: [24, 67, 46, 30] //смотрим в консоль дальше.. эта же строчка, но уже правей. myHTML.html:6 это значит консоль была вызвана на 6 строчке в файле "myHTML.html". т.к. у нас один файл разумеется имя будет одно console.log(array[5]); //обратимся к 5му элементу массива // что нам тут выводит консоль?? undefined. т.к. 5 го элемента массива не существует.. все правильно var n = array[5]; // запишем в переменную 5й элемент массива console.log(n[1]); //выведем 1-й элемен массива n //здесь будет ошибка т.к. "n" - это НЕ массив, а переменная |
Спасибо.Естественно,что не всё понятно,сейчас посмотрю с другими файлами.
|
Часовой пояс GMT +3, время: 11:43. |