The document discusses loops and arrays in JavaScript. It describes the different types of loops - while, do-while and for loops. It provides examples to demonstrate each loop. It also describes arrays, including single and multi-dimensional arrays. It explains how to declare and access array elements. Finally, it discusses various array methods like concat, join, push etc and provides examples to use these methods.
String Function
1. charAt():
This method returns the character from the specified index.Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character in a string called stringName is stringName.length - 1.
Syntax:
string.charAt(index);
Return Value:
Returns the character from the specified index.
Example:
<html>
<head>
<title>JavaScript String charAt() Method</title>
</head>
<body>
</body>
</html>
Output:
str.charAt(0) is:T
2. concat():
Description:
This method adds two or more strings and returns a new single string.
Syntax:
string.concat(string2, string3[, ..., stringN]);
parameters:
string2...stringN : These are the strings to be concatenated.
Return Value:
Returns a single concatenated string.
Example:
<html>
<head>
<title>JavaScript String concat() Method</title>
</head>
<body>
</body>
</html>
Output:
Concatenated String :This is string oneThis is string two.
3. indexOf():
Description:
This method returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex or -1 if the value is not found.
Syntax:
string.indexOf(searchValue[, fromIndex])
Parameters:
searchValue : A string representing the value to search for.
fromIndex : The location within the calling string to start the search from. It can be any integer between 0 and the length of the string. The default value is 0.
Return Value:
Returns the index of the found occurrence otherwise -1 if not found.
Example:
<html>
<head>
<title>JavaScript String indexOf() Method</title>
</head>
<body>
<br />");
var index = str1.indexOf( "one" );
document.write("indexOf found String :" + index );
</body></html>
Oputput:
indexOf found String :8
indexOf found String :15
4. lastIndexOf():
Description:
This method returns the index within the calling String object of the last occurrence of the specified value, starting the search at fromIndex or -1 if the value is not found.
Syntax:
string.lastIndexOf(searchValue[, fromIndex])
Parameters:
searchValue : A string representing the value to search for.
fromIndex : The location within the calling string to start the search from. It can be any integer between 0 and the length of the string. The default value is 0.
Return Value:
Returns the index of the last found occurrence otherwise -1 if not found.
Example:
<html>
<head>
<title>JavaScri
JavaScript String:
The String object lets you work with a series of characters; it wraps Javascript's string primitive data type with a number of helper methods.
As JavaScript automatically converts between string primitives and String objects, you can call any of the helper methods of the String object on a string primitive.
JavaScript Arrays:
The Array object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.
String Function
1. charAt():
This method returns the character from the specified index.Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character in a string called stringName is stringName.length - 1.
Syntax:
string.charAt(index);
Return Value:
Returns the character from the specified index.
Example:
<html>
<head>
<title>JavaScript String charAt() Method</title>
</head>
<body>
</body>
</html>
Output:
str.charAt(0) is:T
2. concat():
Description:
This method adds two or more strings and returns a new single string.
Syntax:
string.concat(string2, string3[, ..., stringN]);
parameters:
string2...stringN : These are the strings to be concatenated.
Return Value:
Returns a single concatenated string.
Example:
<html>
<head>
<title>JavaScript String concat() Method</title>
</head>
<body>
</body>
</html>
Output:
Concatenated String :This is string oneThis is string two.
3. indexOf():
Description:
This method returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex or -1 if the value is not found.
Syntax:
string.indexOf(searchValue[, fromIndex])
Parameters:
searchValue : A string representing the value to search for.
fromIndex : The location within the calling string to start the search from. It can be any integer between 0 and the length of the string. The default value is 0.
Return Value:
Returns the index of the found occurrence otherwise -1 if not found.
Example:
<html>
<head>
<title>JavaScript String indexOf() Method</title>
</head>
<body>
<br />");
var index = str1.indexOf( "one" );
document.write("indexOf found String :" + index );
</body></html>
Oputput:
indexOf found String :8
indexOf found String :15
4. lastIndexOf():
Description:
This method returns the index within the calling String object of the last occurrence of the specified value, starting the search at fromIndex or -1 if the value is not found.
Syntax:
string.lastIndexOf(searchValue[, fromIndex])
Parameters:
searchValue : A string representing the value to search for.
fromIndex : The location within the calling string to start the search from. It can be any integer between 0 and the length of the string. The default value is 0.
Return Value:
Returns the index of the last found occurrence otherwise -1 if not found.
Example:
<html>
<head>
<title>JavaScri
JavaScript String:
The String object lets you work with a series of characters; it wraps Javascript's string primitive data type with a number of helper methods.
As JavaScript automatically converts between string primitives and String objects, you can call any of the helper methods of the String object on a string primitive.
JavaScript Arrays:
The Array object lets you store multiple values in a single variable. It stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.
Things you should know about Javascript ES5. A programming language that enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else
Slides from a tutorial I gave at ETech 2006. Notes to accompany these slides can be found here: http://simonwillison.net/static/2006/js-reintroduction-notes.html
Powerful JavaScript Tips and Best PracticesDragos Ionita
Javascript Best Practices, IIFE, Immediately invoked function expressions, typeof, instanceof, constructor, random items from an array, generate an array of numbers, append an array to another array, is a number, is an array, remove an item from an array
Love it or hate it, JavaScript is playing an increasingly important role in the next generation of web and mobile apps. As code continues to move from the server to the client, JavaScript is being used to do more than simple HTML manipulation. Be prepared for this transition and make sure the JavaScript you write is optimized and ready to perform on desktops and devices! In this session, you will learn ten practical tips that you can use today to write faster, more maintainable, memory friendly JavaScript.
Ten useful JavaScript tips & best practicesAnkit Rastogi
In this presentation there are ten useful JavaScript techniques which can be included in your application easily with less friction along with some AngularJs tips and best practices as a bonus. These tips and best practices are accompanied by examples & will cover script loading, design pattern, performance optimization and other areas.
Since best practices are very subjective topics, proper benchmarking needs to be done.
Things you should know about Javascript ES5. A programming language that enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else
Slides from a tutorial I gave at ETech 2006. Notes to accompany these slides can be found here: http://simonwillison.net/static/2006/js-reintroduction-notes.html
Powerful JavaScript Tips and Best PracticesDragos Ionita
Javascript Best Practices, IIFE, Immediately invoked function expressions, typeof, instanceof, constructor, random items from an array, generate an array of numbers, append an array to another array, is a number, is an array, remove an item from an array
Love it or hate it, JavaScript is playing an increasingly important role in the next generation of web and mobile apps. As code continues to move from the server to the client, JavaScript is being used to do more than simple HTML manipulation. Be prepared for this transition and make sure the JavaScript you write is optimized and ready to perform on desktops and devices! In this session, you will learn ten practical tips that you can use today to write faster, more maintainable, memory friendly JavaScript.
Ten useful JavaScript tips & best practicesAnkit Rastogi
In this presentation there are ten useful JavaScript techniques which can be included in your application easily with less friction along with some AngularJs tips and best practices as a bonus. These tips and best practices are accompanied by examples & will cover script loading, design pattern, performance optimization and other areas.
Since best practices are very subjective topics, proper benchmarking needs to be done.
Most developers have some experience with jQuery, but few of them understand the principles of Javascript and how to write and debug Javascript code. This session will cover best practices for writing object-oriented Javascript, benchmarking, and debugging.
JavaScript - An Introduction is a beginner's guide to JavaScript. It starts with very basic level and goes to intermediate level. You'll be introduced with every language constructs, Event handling, Form handling and AJAX which is supported by JavaScript with XMLHttpRequest object. This XHR object is discussed in enough detail so that you can understand how the underlying AJAX functionality works in jQuery. At the end it discusses advance concepts and library build on/around JavaScript.
GridMate - End to end testing is a critical piece to ensure quality and avoid...ThomasParaiso2
End to end testing is a critical piece to ensure quality and avoid regressions. In this session, we share our journey building an E2E testing pipeline for GridMate components (LWC and Aura) using Cypress, JSForce, FakerJS…
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Sudheer Mechineni, Head of Application Frameworks, Standard Chartered Bank
Discover how Standard Chartered Bank harnessed the power of Neo4j to transform complex data access challenges into a dynamic, scalable graph database solution. This keynote will cover their journey from initial adoption to deploying a fully automated, enterprise-grade causal cluster, highlighting key strategies for modelling organisational changes and ensuring robust disaster recovery. Learn how these innovations have not only enhanced Standard Chartered Bank’s data infrastructure but also positioned them as pioneers in the banking sector’s adoption of graph technology.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionAggregage
Join Maher Hanafi, VP of Engineering at Betterworks, in this new session where he'll share a practical framework to transform Gen AI prototypes into impactful products! He'll delve into the complexities of data collection and management, model selection and optimization, and ensuring security, scalability, and responsible use.
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024Neo4j
Neha Bajwa, Vice President of Product Marketing, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
Communications Mining Series - Zero to Hero - Session 1DianaGray10
This session provides introduction to UiPath Communication Mining, importance and platform overview. You will acquire a good understand of the phases in Communication Mining as we go over the platform with you. Topics covered:
• Communication Mining Overview
• Why is it important?
• How can it help today’s business and the benefits
• Phases in Communication Mining
• Demo on Platform overview
• Q/A
A tale of scale & speed: How the US Navy is enabling software delivery from l...sonjaschweigert1
Rapid and secure feature delivery is a goal across every application team and every branch of the DoD. The Navy’s DevSecOps platform, Party Barge, has achieved:
- Reduction in onboarding time from 5 weeks to 1 day
- Improved developer experience and productivity through actionable findings and reduction of false positives
- Maintenance of superior security standards and inherent policy enforcement with Authorization to Operate (ATO)
Development teams can ship efficiently and ensure applications are cyber ready for Navy Authorizing Officials (AOs). In this webinar, Sigma Defense and Anchore will give attendees a look behind the scenes and demo secure pipeline automation and security artifacts that speed up application ATO and time to production.
We will cover:
- How to remove silos in DevSecOps
- How to build efficient development pipeline roles and component templates
- How to deliver security artifacts that matter for ATO’s (SBOMs, vulnerability reports, and policy evidence)
- How to streamline operations with automated policy checks on container images
Unlocking Productivity: Leveraging the Potential of Copilot in Microsoft 365, a presentation by Christoforos Vlachos, Senior Solutions Manager – Modern Workplace, Uni Systems
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
2. Objectives
Describe while loop.
Explain for loop.
Describe do-while loop.
Explain break and continue statements.
Describe the methods of Array object.
3. What is a loop?
Loop is a section of code in a program which is
executed repeatedly, until a specific condition is
satisfied.
There are three type of loop structures:
The while loop
The do-while loop
The for loop
4. The while loop
The while loop executes a
block of code as long as the
given condition remains Conditio
false
true. n
Syntax:
true
while (condition)
{ Execute
body Exit loop
statement(s); of loop
}
5. The while loop: Demo
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>while loop demo</title>
<script language="javascript" type="text/javascript">
var n=20;
var i=0;
document.write("Display the odd number <br>");
while(i<=n)
{
if(i%2 == 0)
document.write(i + "t");
i++;
}
</script>
</head>
<body>
</body>
</html>
6. The do-while loop
The do-while loop is similar to the
while loop, but the do-while loop do
evaluates the condition at the end of
the loop. So that, the do-while loop Execute
body
executes at least once. of loop
Syntax:
do true
Conditio
n
{
statement(s); false
}while(condition); Exit loop
7. The do-while loop: Demo
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>while loop demo</title>
<script language="javascript" type="text/javascript">
var n=20;
var i=0;
document.write("Display the even number <br>");
do
{
if(i%2 == 0)
document.write(i + "t");
i++;
} while(i<=n);
</script>
</head>
<body>
</body>
</html>
8. The for loop
Syntax:
for(initialization; condition; increment/decrement)
{
statement(s);
}
The initialization is an assignment statement that sets the
loop control variable, before entering the loop.
The condition is a relational expression, which
determines, when the loop will exit.
The increment/decrement defines how the loop control
variable changes, each time the loop is executed.
9. The for loop: Demo
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>for loop demo</title>
<script language="javascript" type="text/javascript">
var n=20;
var i=0;
document.write("Display the even number <br>");
for(i=0; i<n; i++)
{
if(i%2 == 0)
document.write(i + "t");
}
</script>
</head>
<body>
</body>
</html>
10. break statement
The break statement can be used in the switch-
case and loop constructs. It is used to exit the
loop without evaluating the specified condition.
for(initialization; condition; increment/decrement)
{
….
if(condition)
break;
…
}
...
11. break statement: Demo
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Using break statement</title>
<script language="javascript" type="text/javascript">
var n = prompt("Enter the number n:");
var i=0;
for(i=2; i<n; i++)
{
if(n % i == 0)
{
document.write(n + " is not a prime number.");
break;
}
}
if(i == n)
document.write(n + " is prime number.");
</script>
</head>
</html>
12. continue statement
The continue statement is mostly used in the loop
constructs. It is used to terminate the current
execution of the loop and continue with the next
repetition by returning the control to the beginning of
the loop.
for(initialization; condition; increment/decrement)
{
….
if(condition)
continue;
…
}
...
13. continue statement: Demo
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>continue statement demo</title>
<script language="javascript" type="text/javascript">
var n=20;
var i=0;
document.write("Display the even numbers <br>");
for(i=0; i<=n; i++)
{
if(i%2 == 1)
continue;
else
document.write(i + "t");
}
</script>
</head>
</html>
14. Single-dimensional arrays
An array is a collection of values stored in adjacent
memory locations. These array values are referenced
using a common array name.
The values of array are the same data type. These values
can be accessed by using the subscript or index numbers.
The index determines the position of element in the array
list.
In a single-dimensional array, the elements are stored in a
single row in the located memory.
In JavaScript, the first element has the index number zero.
Index
Value
15. Declaring arrays
There are three ways to declaring an array:
Using the Array object: declare an array by using the new
operator, and then initialize the individual array elements:
var arr = new Array(3);
arr[0] = “Single”;
arr[1] = “Married”;
arr[2] = “Divorced”;
Initialize the array variable at the time of declaration:
var arr = new Array(„Single‟,‟Married‟,‟Divorced‟);
Creates an array without using Array object:
var arr = {„Single‟,‟Married‟,‟Divorced‟};
16. Single-dimensional arrays - Demo
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Single-dimensional array</title>
<script language="javascript" type="text/javascript">
var arr = new Array("Lundi", "Mardi", "Mercredi", "Jeudi",
"Vendredi", "Samedi","Dimanche");
document.write("The days in a week <br>");
for(i=0; i<arr.length; i++)
{
document.write(arr[i] + '<BR>');
}
</script>
</head>
</html>
17. Multi-dimensional arrays
A multi-dimensional array stores a combination of values of
a single type in two or more dimensions.
A two-dimensional array represents as rows and columns
similar to a table.
JavaScript does not directly support two-dimensional array.
You can create two-dimensional array by creating an array
of arrays. You first declare an array and then create another
array to each element of the main array.
var emp= new Array(3);
emp[0] = new Array(„John‟,‟300‟);
emp[1] = new Array(„David‟,‟400‟);
emp[2] = new Array(„Richard‟,‟500‟);
19. Array methods
An array is a set of values grouped together an identified by
a single name. In JavaScript, an Array allows you to create
arrays. It provides the length property that is used to
determine the number of elements in an array.
The various methods allow you to access and manipulate
the array elements:
- concat: combines one or more array variables.
- join: joins all the array elements into a string.
- pop: retrieves the last element of an array.
- push: appends one or more elements to the end of an array.
- sort: sorts the array elements in alphabetical order.
- reverse: retrieves the elements from the last to the first index
position.
- toString: converts the array elements into string.
20. Array methods - Demo
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Using method in array</title>
<script language="javascript" type="text/javascript">
var days = new Array('Monday','Tuesday','Wednesday');
document.write('Number of days: ' + days.length + '<br>');
document.write('The days: ' + days.join(', ') + '<br>');
document.write('The days after adding more: ' +
days.push('Thursday','Friday','Saturday') + '<br>');
document.write('The days after sorting:' + days.sort() + '<br>');
document.write('The days after sorting in desceding order:' +
days.reverse() + '<br>');
</script>
</head>
</html>
21. for … in Loop
The for…in loop is an extension of for loop. It enables you
to perform specific actions on the array objects. The loop
reads every element in the specified array and executes a
block of code once for each element in the array.
Example:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Using method in array</title>
<script language="javascript" type="text/javascript">
var arr = new Array("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi",
"Samedi","Dimanche");
document.write('THE DAYS IN A WEEK: <BR>');
for(var i in arr)
{
document.write(arr[i] + '<br>');
}
</script>
</head>
</html>
22. Summary
Loop statements allow to execute the same block
of code multiple times depending whether the
specified condition is sastified or not.
Array is a collection of values of the same type.
Javascript support three types of loop:
While loop
For loop
Do….while loop
Jump statements: break, continue
Building Dynamic Websites/Session 1/ 22 of 16
23. Summary…
There are two types arrays:
Single dimensional arrays
Multiple dimensional arrays
For….in loop is an extension of the for loop.
Building Dynamic Websites/Session 1/ 23 of 16