找到关于面向对象编程的9301篇文章
282 次浏览
假设我们有以下数组对象:var arrayObject = [ "John", "David", "Mike" ]您可以使用length属性将长度设置为0并清除内存。清除内存的语法如下:yourArrayObjectName.length=0; // 清除内存 yourArrayObjectName.length=4; // 分配内存输出这将在控制台中产生以下输出:var arrayObject = [ "John", "David", "Mike" ] arrayObject.length = 0; console.log(arrayObject); arrayObject.length = 5; for (var i = 0; i < arrayObject.length; i++) ... 阅读更多
916 次浏览
您可以使用事件侦听器来监听点击事件。示例以下是代码: 实时演示 文档 第一部分 第二部分 document.addEventListener('click', callEventFuncion) function callEventFuncion(event) { var div = document.querySelectorAll('.divDemo'); var titleResult = document.querySelectorAll('.my-title'); var result = Array.apply(0, div).find((v) => v.contains(event.target)); if (result) { console.log(" 正在增加Div选择"); } else { ... 阅读更多
249 次浏览
为此,使用join()。它将连接字符串值长度-1。示例以下是代码:var count = 5; var values = new Array(count + 1).join('John'); console.log(values); var count1 = 5; var values1 = new Array(count1).join('John'); console.log(values1);要运行上述程序,您需要使用以下命令:node fileName.js。这里,我的文件名是demo274.js。输出这将在控制台中产生以下输出:PS C:\Users\Amit\javascript-code> node demo274.js JohnJohnJohnJohnJohn JohnJohnJohnJohn
946 次浏览
使用展开运算符,允许表达式扩展到多个参数、元素、变量等。您可以使用JSON.stringify()将JavaScript对象转换为字符串。在这里,我们使用展开运算符对details1和details2进行运算后,得到的对象作为结果。示例以下是代码:var details1 = { name: 'John', age: 21 }; var details2 = { countryName: 'US', subjectName:'JavaScript' }; var result= { ...details1, ...details2}; console.log(JSON.stringify(result));要运行上述程序,您需要使用以下命令:node fileName.js。这里,我的文件名是demo267.js。输出这将在控制台中产生以下输出:PS C:\Users\Amit\javascript-code> node demo267.js {"name":"John", "age":21, "countryName":"US", "subjectName":"JavaScript"}阅读更多
167 次浏览
要验证特定的URL,请使用正则表达式。示例代码如下:function validateSoundURL(myURL) { var regularExpression = /^https?:\/\/(tutorialspoint\.com)\/(.*)$/; return myURL.match(regularExpression) && myURL.match(regularExpression)[2] } console.log(validateSoundURL("https://tutorialspoint.com/index")); console.log(validateSoundURL("https://tutorialspoint.com/java"));要运行上述程序,您需要使用以下命令:node fileName.js。这里,我的文件名是demo259.js。输出这将在控制台中产生以下输出:PS C:\Users\Amit\javascript-code> node demo259.js index java
184 次浏览
是的,非非运算符是非运算符的反向过程。如果任何值为true,则单个!(非)将返回false,而!!将返回相反的值(true)。非运算符:var flag=true; console.log(!flag);非非运算符:var flag=true; console.log(!!flag);示例以下是代码:var flag=true; console.log("单!的结果") console.log(!flag); console.log("单!!的结果") console.log(!!flag)要运行上述程序,您需要使用以下命令:node fileName.js。这里,我的文件名是demo247.js输出这将在控制台中产生以下输出:PS C:\Users\Amit\javascript-code> node demo247.js 单!的结果 false 单!!的结果 ... 阅读更多
221 次浏览
当您想将属性定义到对象时,可以使用冒号(:),而当您想将值赋给变量时,可以使用等号(=)。示例以下是代码:var studentDetails = { "studentId": 101, "studentName": "John", "studentSubjectName": "Javascript", "studentCountryName": "US" } console.log(studentDetails); var firstName = "David"; console.log(firstName);要运行上述程序,您需要使用以下命令:node fileName.js。这里,我的文件名是demo325.js。输出这将产生以下输出:PS C:\Users\Amit\javascript-code> node demo325.js { studentId: 101, studentName: 'John', studentSubjectName: 'Javascript', studentCountryName: 'US' } David
228 次浏览
要删除子元素,请将innerHTML设置为“” 。示例以下是代码: 文档 Javascript MySQL 删除项目 remove.onclick = () => { const element = document.getElementById("removeAllChildElements"); element.innerHTML = ''; } 要运行上述程序,请将文件名保存为anyName.html(index.html)。右键单击该文件,并在VS Code编辑器中选择“使用实时服务器打开”选项。输出这将产生以下输出:现在您可以单击“删除项目”按钮。它将删除框内所有元素。输出这将产生以下输出:
106 次浏览
正确使用map()函数来保存元素。示例以下是代码:const addIndexValueToArrayElement = function (arrObject) { const updatedArrayValue = []; arrObject.forEach(function (ob) { const mapValue = ob.map(function (value) { return value + arrObject.indexOf(ob) }) updatedArrayValue.push(mapValue) }) return updatedArrayValue; }; const output = addIndexValueToArrayElement([ [4, 5], [7, 56], [34, 78], ]); console.log(output);要运行上述程序,您需要使用以下命令:node fileName.js。这里,我的文件名是demo323.js。输出这将产生以下输出:PS C:\Users\Amit\javascript-code> node demo323.js [ [ 4, 5 ], [ 8, 57 ], [ 36, 80 ] ]
2K+ 次浏览
要使其工作,您可以将onclick与input type = “submit”一起使用。示例以下是代码: 文档 名字: 提交 var firstName = null; function submitForm(evnt) { evnt.preventDefault(); firstName = document.getElementById("fName").value; document.getElementById("result").innerHTML = "名字是=" + firstName; } 要运行上述程序,请将文件名保存为anyName.html(index.html)。右键单击该文件,并选择... 阅读更多
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP